﻿Imports ADOEntity
Imports System.Data
Imports DevExpress.XtraReports.Parameters
Imports System.IO


Partial Class Form_frmPrintRptMaster
    Inherits System.Web.UI.Page

    Enum enmTypeReport
        'Admin
        rptSystemConfig = 1 '-,-
        rptUserRight = 2 '-,-
        rptMenuRight = 3 '-
        rptDepartment = 4 '-,-
        rptBrach = 5 '-,-
        rptUser = 6 '-
        rptUnLock = 7
        rptHistoryLogin = 8 '-
        rptZone = 9 '-,

        'Admin/ข้อมูลหลัก/Amlo
        rptMTSCTYPE1 = 101
        rptMOBJTYPE = 102
        rptTYPE_ID = 103
        rptMPSNRELATION = 104
        rptMOFFICETYPE = 105
        rptMOFFICEOCC = 106
        rptMASSETTYPE = 107
        rptMRELATION = 108
        rptMTSCTYPE2 = 109
        rptMTSCTYPE3 = 110

        'Admin/ข้อมูลหลัก/KYC
        rptMCUSTSUBTYPE = 201
        rptMMARITALSTATUS = 202
        rptMPOSITION = 203
        rptMBIZRELATION = 204

        rptMBUSINESS = 205
        rptMCHECKEVIDENCE = 206
        rptMNATIONALITY = 207
        rptMOCCUPATION = 208
        rptMPREFIX = 209

        rptMsanctionList = 301
        rptAmlWatchList = 302
    End Enum

    Private strSql As String
    Dim dtb As clsDatabase
    Dim clsVarParameter As clsVariable



    Protected Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles form1.Load
        If Not (IsPostBack) Then
            hdfRptType.Value = Request.Item("rptType")
        End If

        Dim strRptType As String = IIf(hdfRptType.Value = "", 0, hdfRptType.Value)

        If (enmTypeReport.rptSystemConfig = strRptType) Then
            SystemConfig()
        ElseIf (enmTypeReport.rptUserRight = strRptType) Then

            Dim strUserRight As String = ""
            Dim strUserRightDesc As String = ""
            Dim strUserRightStatus As String = ""

            If Not (IsPostBack) Then
                hdfVar1.Value = Request.Item("UserRight")
                hdfVar2.Value = Request.Item("UserRightDesc")
                hdfVar3.Value = Request.Item("UserRightStatus")

                strUserRight = Request.Item("UserRight")
                strUserRightDesc = Request.Item("UserRightDesc")
                strUserRightStatus = Request.Item("UserRightStatus")
            Else
                If Not (IsCallback) Then
                    strUserRight = convertStringEncode(hdfVar1.Value)
                    strUserRightDesc = convertStringEncode(hdfVar2.Value)
                    strUserRightStatus = convertStringEncode(hdfVar3.Value)
                Else
                    strUserRight = hdfVar1.Value
                    strUserRightDesc = hdfVar2.Value
                    strUserRightStatus = hdfVar3.Value
                End If
                
            End If
            UserRight(strUserRight, strUserRightDesc, strUserRightStatus)

        ElseIf (enmTypeReport.rptMenuRight = strRptType) Then

            Dim strUserRight As String = ""
            Dim strUserRightDesc As String = ""
            Dim strUserRightStatus As String = ""

            If Not (IsPostBack) Then
                hdfVar1.Value = Request.Item("UserRight")
                hdfVar2.Value = Request.Item("UserRightDesc")
                hdfVar3.Value = Request.Item("UserRightStatus")

                strUserRight = Request.Item("UserRight")
                strUserRightDesc = Request.Item("UserRightDesc")
                strUserRightStatus = Request.Item("UserRightStatus")
            Else
                If Not (IsCallback) Then
                    strUserRight = convertStringEncode(hdfVar1.Value)
                    strUserRightDesc = convertStringEncode(hdfVar2.Value)
                    strUserRightStatus = convertStringEncode(hdfVar3.Value)
                Else
                    strUserRight = hdfVar1.Value
                    strUserRightDesc = hdfVar2.Value
                    strUserRightStatus = hdfVar3.Value
                End If

            End If
            UserRightMenu(strUserRight, strUserRightDesc, strUserRightStatus)

        ElseIf (enmTypeReport.rptDepartment = strRptType) Then
            Dim strDeptCode As String = ""
            Dim strDeptName As String = ""
          

            If Not (IsPostBack) Then
                strDeptCode = Request.Item("deptCode")
                strDeptName = Request.Item("deptName")

                hdfVar1.Value = strDeptCode
                hdfVar2.Value = strDeptName
            Else
                If Not (IsCallback) Then
                    strDeptCode = convertStringEncode(hdfVar1.Value)
                    strDeptName = convertStringEncode(hdfVar2.Value)
                Else
                    strDeptCode = hdfVar1.Value
                    strDeptName = hdfVar2.Value

                End If
               
            End If
            Department(strDeptCode, strDeptName)
        ElseIf (enmTypeReport.rptBrach = strRptType) Then
            Dim strDeptCode As String = ""
            Dim strZoneCode As String = ""
            Dim strBranchCode As String = ""
            Dim strBranchName As String = ""
         
            If Not (IsPostBack) Then

                strDeptCode = Request.Item("deptCode")
                strZoneCode = Request.Item("zoneCode")
                strBranchCode = Request.Item("BranchCode")
                strBranchName = Request.Item("BranchName")

                hdfVar1.Value = strDeptCode
                hdfVar2.Value = strZoneCode
                hdfVar3.Value = strBranchCode
                hdfVar4.Value = strBranchName
            Else
                If Not (IsCallback) Then
                    strDeptCode = convertStringEncode(hdfVar1.Value)
                    strZoneCode = convertStringEncode(hdfVar2.Value)
                    strBranchCode = convertStringEncode(hdfVar3.Value)
                    strBranchName = convertStringEncode(hdfVar4.Value)
                Else
                    strDeptCode = hdfVar1.Value
                    strZoneCode = hdfVar2.Value
                    strBranchCode = hdfVar3.Value
                    strBranchName = hdfVar4.Value
                End If
                
            End If

            Branch(strDeptCode, strZoneCode, strBranchCode, strBranchName)
        ElseIf (enmTypeReport.rptUser = strRptType) Then
            Dim strDeptCode As String = ""
            Dim strBranchCode As String = ""
            Dim strUserRight As String = ""
            Dim strUserName As String = ""
            Dim strEmpName As String = ""
            Dim strEmpLastName As String = ""
            Dim strIsInactive As String = ""

            If Not (IsPostBack) Then
                strDeptCode = Request.Item("deptCode")
                strBranchCode = Request.Item("BranchCode")
                strUserRight = Request.Item("userRight")
                strUserName = Request.Item("userName")
                strEmpName = Request.Item("empName")
                strEmpLastName = Request.Item("empLastName")
                strIsInactive = Request.Item("isInactive")

                hdfVar1.Value = strDeptCode
                hdfVar2.Value = strBranchCode
                hdfVar3.Value = strUserRight
                hdfVar4.Value = strUserName
                hdfVar5.Value = strEmpName
                hdfVar6.Value = strEmpLastName
                hdfVar7.Value = strIsInactive
            Else
                If Not (IsCallback) Then
                    strDeptCode = convertStringEncode(hdfVar1.Value)
                    strBranchCode = convertStringEncode(hdfVar2.Value)
                    strUserRight = convertStringEncode(hdfVar3.Value)
                    strUserName = convertStringEncode(hdfVar4.Value)
                    strEmpName = convertStringEncode(hdfVar5.Value)
                    strEmpLastName = convertStringEncode(hdfVar6.Value)
                    strIsInactive = convertStringEncode(hdfVar7.Value)
                Else
                    strDeptCode = hdfVar1.Value
                    strBranchCode = hdfVar2.Value
                    strUserRight = hdfVar3.Value
                    strUserName = hdfVar4.Value
                    strEmpName = hdfVar5.Value
                    strEmpLastName = hdfVar6.Value
                    strIsInactive = hdfVar7.Value
                End If
            End If
            userRpt(strDeptCode, strBranchCode, strUserRight, strUserName, strEmpName, strEmpLastName, strIsInactive)
        ElseIf (enmTypeReport.rptUnLock = strRptType) Then
            Dim strDeptCode As String = ""
            Dim strBranchCode As String = ""
            Dim strUserRight As String = ""
            Dim strUserName As String = ""
            Dim strEmpName As String = ""
            Dim strEmpLastName As String = ""
            Dim strLockType As String = ""
            Dim strStartDate As String = ""
            Dim strEndDate As String = ""

            If Not (IsPostBack) Then
                strDeptCode = Request.Item("deptCode")
                strBranchCode = Request.Item("BranchCode")
                strUserRight = Request.Item("userRight")
                strUserName = Request.Item("userName")
                strEmpName = Request.Item("empName")
                strEmpLastName = Request.Item("empLastName")
                strLockType = Request.Item("lockType")
                strStartDate = Request.Item("startDate")
                strEndDate = Request.Item("endDate")

                hdfVar1.Value = strDeptCode
                hdfVar2.Value = strBranchCode
                hdfVar3.Value = strUserRight
                hdfVar4.Value = strUserName
                hdfVar5.Value = strEmpName
                hdfVar6.Value = strEmpLastName
                hdfVar7.Value = strLockType
                hdfVar8.Value = strStartDate
                hdfVar9.Value = strEndDate
            Else
                If Not (IsCallback) Then
                    strDeptCode = convertStringEncode(hdfVar1.Value)
                    strBranchCode = convertStringEncode(hdfVar2.Value)
                    strUserRight = convertStringEncode(hdfVar3.Value)
                    strUserName = convertStringEncode(hdfVar4.Value)
                    strEmpName = convertStringEncode(hdfVar5.Value)
                    strEmpLastName = convertStringEncode(hdfVar6.Value)
                    strLockType = convertStringEncode(hdfVar7.Value)
                    strStartDate = convertStringEncode(hdfVar8.Value)
                    strEndDate = convertStringEncode(hdfVar9.Value)
                Else
                    strDeptCode = hdfVar1.Value
                    strBranchCode = hdfVar2.Value
                    strUserRight = hdfVar3.Value
                    strUserName = hdfVar4.Value
                    strEmpName = hdfVar5.Value
                    strEmpLastName = hdfVar6.Value
                    strLockType = hdfVar7.Value
                    strStartDate = hdfVar8.Value
                    strEndDate = hdfVar9.Value
                End If
            End If
            unlockUserRpt(strDeptCode, strBranchCode, strUserRight, strUserName, strEmpName, strEmpLastName, strLockType, strStartDate, strEndDate)
        ElseIf (enmTypeReport.rptZone = strRptType) Then
            Dim strDeptCode As String = ""
            Dim strZoneCode As String = ""
            Dim strZoneName As String = ""

            If Not (IsPostBack) Then

                strDeptCode = Request.Item("deptCode")
                strZoneCode = Request.Item("zoneCode")
                strZoneName = Request.Item("zoneName")

                hdfVar1.Value = strDeptCode
                hdfVar2.Value = strZoneCode
                hdfVar3.Value = strZoneName
            Else
                If Not (IsCallback) Then
                    strDeptCode = convertStringEncode(hdfVar1.Value)
                    strZoneCode = convertStringEncode(hdfVar2.Value)
                    strZoneName = convertStringEncode(hdfVar3.Value)
                Else
                    strDeptCode = hdfVar1.Value
                    strZoneCode = hdfVar2.Value
                    strZoneName = hdfVar3.Value
                End If
                
            End If
            zone(strDeptCode, strZoneCode, strZoneName)
        ElseIf (enmTypeReport.rptHistoryLogin = strRptType) Then
            Dim strDeptCode As String = ""
            Dim strBranchCode As String = ""
            Dim strUserRight As String = ""
            Dim strUserName As String = ""
            Dim strEmpName As String = ""
            Dim strEmpLastName As String = ""
            Dim strStartDate As String = ""
            Dim strSEndDate As String = ""
            Dim strIsLoginPass As String = ""
            Dim strLogOut As String = ""
            Dim strLoginFalse As String = ""
            If Not (IsPostBack) Then
                strDeptCode = Request.Item("deptCode")
                strBranchCode = Request.Item("branchCode")
                strUserRight = Request.Item("userRight")
                strUserName = Request.Item("userName")
                strEmpName = Request.Item("empName")
                strEmpLastName = Request.Item("empLastName")
                strStartDate = Request.Item("startDate")
                strSEndDate = Request.Item("sEndDate")
                strIsLoginPass = Request.Item("isLoginPass")
                strLogOut = Request.Item("logOut")
                strLoginFalse = Request.Item("LoginFalse")

                hdfVar1.Value = strDeptCode
                hdfVar2.Value = strBranchCode
                hdfVar3.Value = strUserRight
                hdfVar4.Value = strUserName
                hdfVar5.Value = strEmpName
                hdfVar6.Value = strEmpLastName
                hdfVar7.Value = strStartDate
                hdfVar8.Value = strSEndDate
                hdfVar9.Value = strIsLoginPass
                hdfVar10.Value = strLogOut
                hdfVar11.Value = strLoginFalse
            Else
                If Not (IsCallback) Then
                    strDeptCode = convertStringEncode(hdfVar1.Value)
                    strBranchCode = convertStringEncode(hdfVar2.Value)
                    strUserRight = convertStringEncode(hdfVar3.Value)
                    strUserName = convertStringEncode(hdfVar4.Value)
                    strEmpName = convertStringEncode(hdfVar5.Value)
                    strEmpLastName = convertStringEncode(hdfVar6.Value)
                    strStartDate = convertStringEncode(hdfVar7.Value)
                    strSEndDate = convertStringEncode(hdfVar8.Value)
                    strIsLoginPass = convertStringEncode(hdfVar9.Value)
                    strLogOut = convertStringEncode(hdfVar10.Value)
                    strLoginFalse = convertStringEncode(hdfVar11.Value)
                Else
                    strDeptCode = hdfVar1.Value
                    strBranchCode = hdfVar2.Value
                    strUserRight = hdfVar3.Value
                    strUserName = hdfVar4.Value
                    strEmpName = hdfVar5.Value
                    strEmpLastName = hdfVar6.Value
                    strStartDate = hdfVar7.Value
                    strSEndDate = hdfVar8.Value
                    strIsLoginPass = hdfVar9.Value
                    strLogOut = hdfVar10.Value
                    strLoginFalse = hdfVar11.Value
                End If
                

            End If
            HistoryLoginrpt(strDeptCode, strBranchCode, strUserRight, _
                            strUserName, strEmpName, strEmpLastName, _
                            strStartDate, strSEndDate, strIsLoginPass, _
                           strLogOut, strLoginFalse)

        ElseIf (enmTypeReport.rptMTSCTYPE1 = strRptType) Then
            MTSCTYPE1("", "")
        ElseIf (enmTypeReport.rptMOBJTYPE = strRptType) Then
            MOBJTYPE("", "")
        ElseIf (enmTypeReport.rptTYPE_ID = strRptType) Then
            TYPE_ID("", "")
        ElseIf (enmTypeReport.rptMPSNRELATION = strRptType) Then
            MPSNRELATION()
        ElseIf (enmTypeReport.rptMOFFICETYPE = strRptType) Then
            MOFFICETYPE()
        ElseIf (enmTypeReport.rptMOFFICEOCC = strRptType) Then
            MOFFICEOCC()
        ElseIf (enmTypeReport.rptMASSETTYPE = strRptType) Then
            MASSETTYPE()
        ElseIf (enmTypeReport.rptMRELATION = strRptType) Then
            MRELATION()
        ElseIf (enmTypeReport.rptMTSCTYPE2 = strRptType) Then
            MTSCTYPE2()
        ElseIf (enmTypeReport.rptMTSCTYPE3 = strRptType) Then
            MTSCTYPE3()
        ElseIf (enmTypeReport.rptMCUSTSUBTYPE = strRptType) Then
            MCUSTSUBTYPE()
        ElseIf (enmTypeReport.rptMMARITALSTATUS = strRptType) Then
            MMARITALSTATUS()
        ElseIf (enmTypeReport.rptMPOSITION = strRptType) Then
            MPOSITION()
        ElseIf (enmTypeReport.rptMBIZRELATION = strRptType) Then
            MBIZRELATION()
        ElseIf (enmTypeReport.rptMBUSINESS = strRptType) Then
            MBUSINESS()
        ElseIf (enmTypeReport.rptMCHECKEVIDENCE = strRptType) Then
            MCHECKEVIDENCE()
        ElseIf (enmTypeReport.rptMNATIONALITY = strRptType) Then
            MNATIONALITY()
        ElseIf (enmTypeReport.rptMOCCUPATION = strRptType) Then
            MOCCUPATION()
        ElseIf (enmTypeReport.rptMPREFIX = strRptType) Then
            MPREFIX()
        ElseIf (enmTypeReport.rptMsanctionList = strRptType) Then
            Dim strLastUpdateDate As String = ""
            Dim strDataSource As String = ""
            Dim strShowDetail As String = ""

            If Not (IsPostBack) Then
                strLastUpdateDate = Request.Item("lastUpdateDate")
                strDataSource = Request.Item("datasource")
                strShowDetail = Request.Item("ShowDetail")

                hdfVar1.Value = strLastUpdateDate
                hdfVar2.Value = strDataSource
                hdfVar3.Value = strShowDetail
            Else
                If Not (IsCallback) Then
                    strLastUpdateDate = convertStringEncode(hdfVar1.Value)
                    strDataSource = convertStringEncode(hdfVar2.Value)
                    strShowDetail = convertStringEncode(hdfVar3.Value)
                Else
                    strLastUpdateDate = hdfVar1.Value
                    strDataSource = hdfVar2.Value
                    strShowDetail = hdfVar3.Value

                End If

            End If
            Sanction_List(strLastUpdateDate, strDataSource, strShowDetail)
        ElseIf (enmTypeReport.rptAmlWatchList = strRptType) Then
            Dim strListType As String = ""
            If Not (IsPostBack) Then
                strListType = Request.Item("ListType")
                hdfVar1.Value = strListType
            Else
                If Not (IsCallback) Then
                    strListType = convertStringEncode(hdfVar1.Value)
                Else
                    strListType = hdfVar1.Value
                End If
            End If
            AMLWatch_List(strListType)
        Else

        End If

    End Sub

    Private Function convertStringEncode(ByVal strCon As String) As String
        Dim rtStr As String = ""
        Try

            rtStr = Encoding.UTF8.GetString(Encoding.GetEncoding("tis-620").GetBytes(strCon))
        Catch ex As Exception
            Throw ex
        End Try
        Return rtStr
    End Function

#Region " Administrator "

    Private Sub UserRight(ByVal strUserRight As String, ByVal strUserRightDesc As String, ByVal strUserRightStatus As String)

        Dim clsSessionMenuRight As New clsSessionMenuRight
        Dim colVarParameter As Collection = New Collection
        Dim StrWhere As String = ""
        Dim strConcat As String = " where "
        Dim strPrmCondition As String = ""
        Dim re As rptUserRight = New rptUserRight

        clsSessionMenuRight = Session("ClsMenuRight")

        If (clsSessionMenuRight.getRoleGroup > 89) Then
            StrWhere = String.Format("{0}{1}(ur.ROLEGHB = 1 or ur.ROLESYS = 1 or ur.ROLEDEPT = 1 or ur.ROLEZONE= 1 Or ur.ROLEBRANCH = 1 Or ur.ROLEUSER = 1) ", _
                                          StrWhere, _
                                          strConcat)
            strConcat = " And "
            '    'qryUserRight = qryUserRight.Where(Function(fn) fn.ROLEGHB = 1)
        ElseIf (clsSessionMenuRight.getRoleGroup > 79) Then
            StrWhere = String.Format("{0}{1}(ur.ROLESYS = 1 or ur.ROLEDEPT = 1 or ur.ROLEZONE= 1 Or ur.ROLEBRANCH = 1 Or ur.ROLEUSER = 1) ", _
                                       StrWhere, _
                                       strConcat)
            strConcat = " And "
            '    'qryUserRight = qryUserRight.Where(Function(fn) fn.ROLESYS = 1)
        ElseIf (clsSessionMenuRight.getRoleGroup > 69) Then
            StrWhere = String.Format("{0}{1}(ur.ROLEDEPT = 1 or ur.ROLEZONE= 1 Or ur.ROLEBRANCH = 1 Or ur.ROLEUSER = 1) ", _
                                      StrWhere, _
                                      strConcat)
            strConcat = " And "

            '    qryUserRight = qryUserRight.Where(Function(fn) (fn.ROLEDEPT = 1 Or fn.ROLEZONE = 1 Or fn.ROLEBRANCH = 1 Or fn.ROLEUSER = 1) And fn.DEPTCODE = clsSessionMenuRight.getDeptCode)

        ElseIf (clsSessionMenuRight.getRoleGroup > 59) Then

            StrWhere = String.Format("{0}{1}(ur.ROLEZONE= 1 Or ur.ROLEBRANCH = 1 Or ur.ROLEUSER = 1) ", _
                                      StrWhere, _
                                      strConcat)


            '    qryUserRight = qryUserRight.Where(Function(fn) (fn.ROLEZONE = 1 Or fn.ROLEBRANCH = 1 Or fn.ROLEUSER = 1) And fn.DEPTCODE = clsSessionMenuRight.getDeptCode)
        ElseIf (clsSessionMenuRight.getRoleGroup > 49) Then

            StrWhere = String.Format("{0}{1}(ur.ROLEBRANCH = 1 Or ur.ROLEUSER = 1) ", _
                                      StrWhere, _
                                      strConcat)


            '    qryUserRight = qryUserRight.Where(Function(fn) (fn.ROLEBRANCH = 1 Or fn.ROLEUSER = 1) And fn.DEPTCODE = clsSessionMenuRight.getDeptCode)
        ElseIf (clsSessionMenuRight.getRoleGroup < 50) Then

            StrWhere = String.Format("{0}{1}ur.ROLEUSER = 1 ", _
                                      StrWhere, _
                                      strConcat)

            '    qryUserRight = qryUserRight.Where(Function(fn) fn.ROLEUSER = 1)
        End If

        'StrWhere = String.Format("{0}{1}mr.ISSHOW = 1", _
        '                         StrWhere, _
        '                         strConcat)
        'strConcat = " And "



        If Not strUserRight = "" Then
            StrWhere = String.Format("{0}{1}ur.USERRIGHT like '%' || :USERRIGHT || '%'", StrWhere, strConcat)
            strConcat = " And "

            clsVarParameter = New clsVariable() With {.nameColumn = "USERRIGHT", _
                                                      .valueColumn = strUserRight}
            colVarParameter.Add(clsVarParameter)
            'If (strPrmCondition = "") Then
            '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtUserRightCode, strUserRight)
            'Else
            '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtUserRightCode, strUserRight)
            'End If

        Else
            'If (strPrmCondition = "") Then
            '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtUserRightCode, "-")
            'Else
            '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtUserRightCode, "-")
            'End If
        End If

        If Not strUserRightDesc = "" Then
            StrWhere = String.Format("{0}{1}ur.USERRIGHTDESC like '%' || :USERRIGHTDESC || '%'", _
                                     StrWhere, _
                                     strConcat)
            strConcat = " And "
            clsVarParameter = New clsVariable() With {.nameColumn = "USERRIGHTDESC", _
                                                      .valueColumn = strUserRightDesc}
            colVarParameter.Add(clsVarParameter)
            'If (strPrmCondition = "") Then
            '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtUserRightName, strUserRightDesc)
            'Else
            '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtUserRightName, strUserRightDesc)
            'End If

        Else
            'If (strPrmCondition = "") Then
            '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtUserRightName, "-")
            'Else
            '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtUserRightName, "-")
            'End If
        End If

        If strUserRight = "" And strUserRightDesc = "" Then
            re.prmUserRight.Value = " ทั้งหมด "
        Else
            re.prmUserRight.Value = strUserRight & " ( " & strUserRightDesc & " ) "
        End If

        Dim arrUserRightStatus As String() = Nothing
        If Not strUserRightStatus = "" Then
            arrUserRightStatus = strUserRightStatus.Split("/")
            If Not arrUserRightStatus(0) = "-1" Then
                StrWhere = String.Format("{0}{1}ur.STATUS = :USERRIGHTSTATUS", _
                                         StrWhere, _
                                         strConcat)
                strConcat = " And "
                clsVarParameter = New clsVariable() With {.nameColumn = "USERRIGHTSTATUS", _
                                                          .valueColumn = CInt(arrUserRightStatus(0))}
                colVarParameter.Add(clsVarParameter)
                'If (strPrmCondition = "") Then
                '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtUserRightStatus, arrUserRightStatus(1))
                'Else
                '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtUserRightStatus, arrUserRightStatus(1))
                'End If
                re.prmStatus.Value = arrUserRightStatus(1)
            Else
                re.prmStatus.Value = arrUserRightStatus(1)
                'If (strPrmCondition = "") Then
                '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtUserRightStatus, "-")
                'Else
                '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtUserRightStatus, "-")
                'End If
            End If
        End If

        '-------------------------------------------------------------------------------------------------------

        strSql = "SELECT ur.USERRIGHT, ur.USERRIGHTDESC, ur.ROLEGHB, ur.ROLESYS, ur.ROLEDEPT, ur.ROLEZONE, ur.ROLEBRANCH, ur.ROLEUSER, ur.STATUS,  " _
& "                      dm.DEPTCODE, dm.DEPTNAME " _
& "FROM         " & System.Configuration.ConfigurationSettings.AppSettings("TableSUSERRIGHT") & " ur LEFT OUTER JOIN " _
& "                      " & System.Configuration.ConfigurationSettings.AppSettings("TableUSERRIGHTDEPT") & " urd ON ur.USERRIGHT = urd.USERRIGHT LEFT OUTER JOIN " _
& "                     " & System.Configuration.ConfigurationSettings.AppSettings("TableSDEPARTMENT") & " dm ON urd.DEPTCODE = dm.DEPTCODE  " _
& StrWhere _
& " order by ur.USERRIGHT asc"


        Dim ds As New dsAdminMaster
        Dim cls As New clsConnToDbByReport


        cls.rptUserRight(re, strSql, ds, colVarParameter)
        re.prmWhere.Value = strPrmCondition
        ReportViewer1.Report = re


    End Sub


    Private Sub UserRightMenu(ByVal strUserRight As String, ByVal strUserRightDesc As String, ByVal strUserRightStatus As String)

        Dim clsSessionMenuRight As New clsSessionMenuRight
        Dim colVarParameter As Collection = New Collection
        Dim StrWhere As String = ""
        Dim strConcat As String = " where "
        Dim strPrmCondition As String = ""
        Dim re As rptUserRightDetail = New rptUserRightDetail

        clsSessionMenuRight = Session("ClsMenuRight")

        If (clsSessionMenuRight.getRoleGroup > 89) Then
            StrWhere = String.Format("{0}{1}(ur.ROLEGHB = 1 or ur.ROLESYS = 1 or ur.ROLEDEPT = 1 or ur.ROLEZONE= 1 Or ur.ROLEBRANCH = 1 Or ur.ROLEUSER = 1) ", _
                                          StrWhere, _
                                          strConcat)
            strConcat = " And "
            '    'qryUserRight = qryUserRight.Where(Function(fn) fn.ROLEGHB = 1)
        ElseIf (clsSessionMenuRight.getRoleGroup > 79) Then
            StrWhere = String.Format("{0}{1}(ur.ROLESYS = 1 or ur.ROLEDEPT = 1 or ur.ROLEZONE= 1 Or ur.ROLEBRANCH = 1 Or ur.ROLEUSER = 1) ", _
                                       StrWhere, _
                                       strConcat)
            strConcat = " And "
            '    'qryUserRight = qryUserRight.Where(Function(fn) fn.ROLESYS = 1)
        ElseIf (clsSessionMenuRight.getRoleGroup > 69) Then
            StrWhere = String.Format("{0}{1}(ur.ROLEDEPT = 1 or ur.ROLEZONE= 1 Or ur.ROLEBRANCH = 1 Or ur.ROLEUSER = 1) ", _
                                      StrWhere, _
                                      strConcat)
            strConcat = " And "

            '    qryUserRight = qryUserRight.Where(Function(fn) (fn.ROLEDEPT = 1 Or fn.ROLEZONE = 1 Or fn.ROLEBRANCH = 1 Or fn.ROLEUSER = 1) And fn.DEPTCODE = clsSessionMenuRight.getDeptCode)

        ElseIf (clsSessionMenuRight.getRoleGroup > 59) Then

            StrWhere = String.Format("{0}{1}(ur.ROLEZONE= 1 Or ur.ROLEBRANCH = 1 Or ur.ROLEUSER = 1) ", _
                                      StrWhere, _
                                      strConcat)


            '    qryUserRight = qryUserRight.Where(Function(fn) (fn.ROLEZONE = 1 Or fn.ROLEBRANCH = 1 Or fn.ROLEUSER = 1) And fn.DEPTCODE = clsSessionMenuRight.getDeptCode)
        ElseIf (clsSessionMenuRight.getRoleGroup > 49) Then

            StrWhere = String.Format("{0}{1}(ur.ROLEBRANCH = 1 Or ur.ROLEUSER = 1) ", _
                                      StrWhere, _
                                      strConcat)


            '    qryUserRight = qryUserRight.Where(Function(fn) (fn.ROLEBRANCH = 1 Or fn.ROLEUSER = 1) And fn.DEPTCODE = clsSessionMenuRight.getDeptCode)
        ElseIf (clsSessionMenuRight.getRoleGroup < 50) Then

            StrWhere = String.Format("{0}{1}ur.ROLEUSER = 1 ", _
                                      StrWhere, _
                                      strConcat)

            '    qryUserRight = qryUserRight.Where(Function(fn) fn.ROLEUSER = 1)
        End If

        StrWhere = String.Format("{0}{1}mr.ISSHOW = 1", _
                                 StrWhere, _
                                 strConcat)
        strConcat = " And "



        If Not strUserRight = "" Then
            StrWhere = String.Format("{0}{1}ur.USERRIGHT like '%' || :USERRIGHT || '%'", StrWhere, strConcat)
            strConcat = " And "

            clsVarParameter = New clsVariable() With {.nameColumn = "USERRIGHT", _
                                                      .valueColumn = strUserRight}
            colVarParameter.Add(clsVarParameter)
            'If (strPrmCondition = "") Then
            '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtUserRightCode, strUserRight)
            'Else
            '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtUserRightCode, strUserRight)
            'End If

        Else
            'If (strPrmCondition = "") Then
            '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtUserRightCode, "-")
            'Else
            '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtUserRightCode, "-")
            'End If
        End If

        If Not strUserRightDesc = "" Then
            StrWhere = String.Format("{0}{1}ur.USERRIGHTDESC like '%' || :USERRIGHTDESC || '%'", _
                                     StrWhere, _
                                     strConcat)
            strConcat = " And "
            clsVarParameter = New clsVariable() With {.nameColumn = "USERRIGHTDESC", _
                                                      .valueColumn = strUserRightDesc}
            colVarParameter.Add(clsVarParameter)
            'If (strPrmCondition = "") Then
            '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtUserRightName, strUserRightDesc)
            'Else
            '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtUserRightName, strUserRightDesc)
            'End If

        Else
            'If (strPrmCondition = "") Then
            '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtUserRightName, "-")
            'Else
            '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtUserRightName, "-")
            'End If
        End If

        If strUserRight = "" And strUserRightDesc = "" Then
            re.prmUserRight.Value = " ทั้งหมด "
        Else
            re.prmUserRight.Value = strUserRight & " ( " & strUserRightDesc & " ) "
        End If

        Dim arrUserRightStatus As String() = Nothing
        If Not strUserRightStatus = "" Then
            arrUserRightStatus = strUserRightStatus.Split("/")
            If Not arrUserRightStatus(0) = "-1" Then
                StrWhere = String.Format("{0}{1}ur.STATUS = :USERRIGHTSTATUS", _
                                         StrWhere, _
                                         strConcat)
                strConcat = " And "
                clsVarParameter = New clsVariable() With {.nameColumn = "USERRIGHTSTATUS", _
                                                          .valueColumn = CInt(arrUserRightStatus(0))}
                colVarParameter.Add(clsVarParameter)
                'If (strPrmCondition = "") Then
                '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtUserRightStatus, arrUserRightStatus(1))
                'Else
                '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtUserRightStatus, arrUserRightStatus(1))
                'End If
                re.prmStatus.Value = arrUserRightStatus(1)
            Else
                re.prmStatus.Value = arrUserRightStatus(1)
                'If (strPrmCondition = "") Then
                '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtUserRightStatus, "-")
                'Else
                '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtUserRightStatus, "-")
                'End If
            End If
        End If

        '-------------------------------------------------------------------------------------------------------

        strSql = "SELECT ur.USERRIGHT, ur.USERRIGHTDESC, ur.ROLEGHB, ur.ROLESYS, ur.ROLEDEPT, ur.ROLEZONE, ur.ROLEBRANCH, ur.ROLEUSER, ur.STATUS,  " _
& "                      pg.PROGRAMCODE, pg.PROGRAMNAME, mr.ISSHOW, mr.MQUERY, mr.MADD, mr.MMODIFY, mr.MDELETE, mr.MPRINT " _
& "FROM         " & System.Configuration.ConfigurationSettings.AppSettings("TableSUSERRIGHT") & " ur LEFT OUTER JOIN " _
& "                      " & System.Configuration.ConfigurationSettings.AppSettings("TableSMENURIGHT") & " mr ON ur.USERRIGHT = mr.USERRIGHT LEFT OUTER JOIN " _
& "                      " & System.Configuration.ConfigurationSettings.AppSettings("TableSPROGRAM") & " pg ON mr.PROGRAMCODE = pg.PROGRAMCODE " _
& StrWhere _
& " order by ur.USERRIGHT,pg.PROGRAMCODE asc "


        Dim ds As New dsAdminMaster
        Dim cls As New clsConnToDbByReport


        cls.rptUserRight(re, strSql, ds, colVarParameter)
        re.prmWhere.Value = strPrmCondition
        ReportViewer1.Report = re



    End Sub


    Private Sub Department(ByVal strDeptCode As String, ByVal strDeptName As String)
        Dim colVarParameter As Collection = New Collection
        Dim StrWhere As String = ""
        Dim strConcat As String = " where "
        Dim strPrmCondition As String = ""


        If Not strDeptCode = "" Then
            StrWhere = String.Format("{0}{1}DEPTCODE like '%' || :DEPTCODE || '%'", StrWhere, strConcat)
            strConcat = " And "

            clsVarParameter = New clsVariable() With {.nameColumn = "DEPTCODE", _
                                                      .valueColumn = strDeptCode}
            colVarParameter.Add(clsVarParameter)

            If (strPrmCondition = "") Then
                strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtDeptCode, strDeptCode)
            Else
                strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtDeptCode, strDeptCode)
            End If

        Else
            If (strPrmCondition = "") Then
                strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtDeptCode, "-")
            Else
                strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtDeptCode, "-")
            End If
        End If


        If Not strDeptName = "" Then
            StrWhere = String.Format("{0}{1}DEPTNAME like '%' || :DEPTNAME  || '%'", _
                                     StrWhere, _
                                     strConcat)
            strConcat = " And "
            clsVarParameter = New clsVariable() With {.nameColumn = "DEPTNAME", _
                                                      .valueColumn = strDeptName}
            colVarParameter.Add(clsVarParameter)
            If (strPrmCondition = "") Then
                strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtDeptName, strDeptName)
            Else
                strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtDeptName, strDeptName)
            End If

        Else
            If (strPrmCondition = "") Then
                strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtDeptName, "-")
            Else
                strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtDeptName, "-")
            End If
        End If

        strSql = "   SELECT     DEPTCODE, DEPTNAME" _
                & "  FROM " & System.Configuration.ConfigurationSettings.AppSettings("TableSDEPARTMENT") & " " _
& StrWhere _
 & " order by DEPTCODE "


        Dim ds As New dsAdminMaster
        Dim cls As New clsConnToDbByReport
        Dim re As rptDepartment = New rptDepartment

        cls.rptDepartment(re, strSql, ds, colVarParameter)
        re.prmWhere.Value = strPrmCondition
        ReportViewer1.Report = re




    End Sub

    Private Sub zone(ByVal strDeptCode As String, ByVal strZoneCode As String, ByVal strZoneName As String)
        Dim colVarParameter As Collection = New Collection
        Dim StrWhere As String = ""
        Dim strConcat As String = " where "
        Dim strPrmCondition As String = ""
        Dim arrDepCode As String() = Nothing

        Dim re As rptZone = New rptZone



        StrWhere = String.Format("{0}{1}not zn.ZONECODE = 'ZZZ'", _
                                StrWhere, _
                                strConcat)
        strConcat = " And "


        '----------------------------------------------------------------------------------------------------
        If Not strDeptCode = "" Then
            arrDepCode = strDeptCode.Split("/")
            If Not arrDepCode(0) = "0" Then
                StrWhere = String.Format("{0}{1}dp.DEPTCODE = :DEPTCODE", StrWhere, strConcat)
                strConcat = " And "

                clsVarParameter = New clsVariable() With {.nameColumn = "DEPTCODE", _
                                                          .valueColumn = arrDepCode(0)}
                colVarParameter.Add(clsVarParameter)
                'If (strPrmCondition = "") Then
                '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtDept, arrDepCode(1))
                'Else
                '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtDept, arrDepCode(1))
                'End If
                re.prmDepCode.Value = arrDepCode(0)
                re.prmDepName.Value = arrDepCode(1)
            Else
                re.prmDepCode.Value = " - "
                re.prmDepName.Value = " - "
                'If (strPrmCondition = "") Then
                '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtDept, "-")
                'Else
                '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtDept, "-")
                'End If
            End If
        End If

        If Not strZoneCode = "" Then
            StrWhere = String.Format("{0}{1}zn.ZONECODE like '%' || :ZONECODE || '%'", _
                                     StrWhere, _
                                     strConcat)
            strConcat = " And "
            clsVarParameter = New clsVariable() With {.nameColumn = "ZONECODE", _
                                                      .valueColumn = strZoneCode}
            colVarParameter.Add(clsVarParameter)
            'If (strPrmCondition = "") Then
            '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtZoneCode, strZoneCode)
            'Else
            '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtZoneCode, strZoneCode)
            'End If

        Else
            'If (strPrmCondition = "") Then
            '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtZoneCode, "-")
            'Else
            '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtZoneCode, "-")
            'End If
        End If

        If Not strZoneName = "" Then
            StrWhere = String.Format("{0}{1}zn.ZONENAME like '%' || :ZONENAME || '%'", _
                                     StrWhere, _
                                     strConcat)
            strConcat = " And "
            clsVarParameter = New clsVariable() With {.nameColumn = "ZONENAME", _
                                                      .valueColumn = strZoneName}
            colVarParameter.Add(clsVarParameter)
            'If (strPrmCondition = "") Then
            '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtZoneName, strZoneName)
            'Else
            '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtZoneName, strZoneName)
            'End If

        Else
            'If (strPrmCondition = "") Then
            '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtZoneName, "-")
            'Else
            '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtZoneName, "-")
            'End If
        End If


        'strSql = " SELECT     dp.DEPTCODE, dp.DEPTNAME, zn.ZONECODE, zn.ZONENAME " _
        '         & " FROM        " & System.Configuration.ConfigurationSettings.AppSettings("TableSDEPARTMENT") & " dp INNER JOIN " _
        '         & "                     " & System.Configuration.ConfigurationSettings.AppSettings("TableSBRANCH") & " br ON dp.DEPTCODE = br.DEPTCODE INNER JOIN " _
        '         & "                      " & System.Configuration.ConfigurationSettings.AppSettings("TableSZONE") & " zn ON br.ZONECODE = zn.ZONECODE " _
        '         & StrWhere _
        '         & " Group By dp.DEPTCODE, dp.DEPTNAME, zn.ZONECODE, zn.ZONENAME " _
        '         & " Order by dp.DEPTCODE, zn.zonecode "

        strSql = " SELECT     dp.DEPTCODE, dp.DEPTNAME, zn.ZONECODE, zn.ZONENAME " _
                  & " FROM        " & System.Configuration.ConfigurationSettings.AppSettings("TableSDEPARTMENT") & " dp INNER JOIN " _
                  & "                      " & System.Configuration.ConfigurationSettings.AppSettings("TableSZONE") & " zn ON dp.DEPTCODE = zn.DEPTCODE " _
                  & StrWhere _
                  & " Group By dp.DEPTCODE, dp.DEPTNAME, zn.ZONECODE, zn.ZONENAME " _
                  & " Order by dp.DEPTCODE, zn.zonecode "


        Dim ds As New dsAdminMaster
        Dim cls As New clsConnToDbByReport

        ' re.prmWhere.Value = strPrmCondition
        cls.rptZone(re, strSql, ds, colVarParameter)
        ReportViewer1.Report = re

    End Sub

    Private Sub SystemConfig()

        strSql = "  SELECT     CONFIGCODE, CONFIGDESC, CONFIGNUM, CONFIGSTR, CONFIGSELECT, configIndex " _
                & " from " & System.Configuration.ConfigurationSettings.AppSettings("TableSSYSTEMCONFIG") & " " _
                & " order by configindex "

        Dim ds As New dsAdminMaster
        Dim cls As New clsConnToDbByReport
        Dim re As rptSystemConfig = New rptSystemConfig

        'Dim prm As DevExpress.XtraReports.Parameters.Parameter = New DevExpress.XtraReports.Parameters.Parameter

        'prm.Name = "prmTest"
        'prm.ParameterType = ParameterType.String
        'prm.Value = "test"
        'prm.Visible = True

        cls.rptSystemConfig(re, strSql, ds)


        re.RequestParameters = True
        ReportViewer1.Report = re

    End Sub

    Private Sub Branch(ByVal strDeptCode As String, ByVal strZoneCode As String, _
                       ByVal strBranchCode As String, ByVal strBranchName As String)

        Dim colVarParameter As Collection = New Collection
        Dim StrWhere As String = ""
        Dim strConcat As String = " where "
        Dim strPrmCondition As String = ""

        Dim re As rptBranch = New rptBranch
        Dim arrDepCode As String() = Nothing
        Dim arrZoneCode As String() = Nothing

        If Not strDeptCode = "" Then
            arrDepCode = strDeptCode.Split("/")
            If Not arrDepCode(0) = "0" Then
                StrWhere = String.Format("{0}{1}SDEPARTMENT.DEPTCODE = :DEPTCODE", StrWhere, strConcat)
                strConcat = " And "

                clsVarParameter = New clsVariable() With {.nameColumn = "DEPTCODE", _
                                                          .valueColumn = arrDepCode(0)}
                colVarParameter.Add(clsVarParameter)
                re.prmDep.Value = arrDepCode(1)
                'If (strPrmCondition = "") Then
                '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtDept, arrDepCode(1))
                'Else
                '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtDept, arrDepCode(1))
                'End If
            Else
                re.prmDep.Value = " - "
                'If (strPrmCondition = "") Then
                '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtDept, "-")
                'Else
                '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtDept, "-")
                'End If
            End If
        End If



        If Not strZoneCode = "" Then
            arrZoneCode = strZoneCode.Split("/")
            If Not arrZoneCode(0) = "ZZZ" Then
                StrWhere = String.Format("{0}{1}SBRANCH.ZONECODE = :ZONECODE", _
                                         StrWhere, _
                                         strConcat)
                strConcat = " And "
                clsVarParameter = New clsVariable() With {.nameColumn = "ZONECODE", _
                                                          .valueColumn = arrZoneCode(0)}
                colVarParameter.Add(clsVarParameter)

                'If (strPrmCondition = "") Then
                '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtZone, arrZoneCode(1))
                'Else
                '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtZone, arrZoneCode(1))
                'End If
                re.prmBranch.Value = arrZoneCode(1)
            Else
                re.prmBranch.Value = " - "
                'If (strPrmCondition = "") Then
                '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtZone, "-")
                'Else
                '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtZone, "-")
                'End If

            End If
        End If



        If Not strBranchCode = "" Then
            StrWhere = String.Format("{0}{1}SBRANCH.BRANCHCODE like '%' || :BRANCHCODE || '%'", _
                                     StrWhere, _
                                     strConcat)
            strConcat = " And "
            clsVarParameter = New clsVariable() With {.nameColumn = "BRANCHCODE", _
                                                      .valueColumn = strBranchCode}
            colVarParameter.Add(clsVarParameter)
            'If (strPrmCondition = "") Then
            '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtBranchCode, strBranchCode)
            'Else
            '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtBranchCode, strBranchCode)
            'End If
        Else
            'If (strPrmCondition = "") Then
            '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtBranchCode, "-")
            'Else
            '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtBranchCode, "-")
            'End If
        End If

        If Not strBranchName = "" Then
            StrWhere = String.Format("{0}{1}SBRANCH.BRANCHNAME like '%' || :BRANCHNAME || '%'", _
                                     StrWhere, _
                                     strConcat)
            strConcat = " And "
            clsVarParameter = New clsVariable() With {.nameColumn = "BRANCHNAME", _
                                                      .valueColumn = strBranchName}
            colVarParameter.Add(clsVarParameter)

            'If (strPrmCondition = "") Then
            '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtBranchName, strBranchName)
            'Else
            '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtBranchName, strBranchName)
            'End If
        Else
            'If (strPrmCondition = "") Then
            '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtBranchName, "-")
            'Else
            '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtBranchName, "-")
            'End If
        End If

        strSql = " SELECT SDEPARTMENT.DEPTCODE, SDEPARTMENT.DEPTNAME, " _
                & "       SBRANCH.BRANCHCODE, SBRANCH.BRANCHNAME, SBRANCH.SOL_ID, SBRANCH.CBS_SOL_ID, " _
                & "       SBRANCH.ZONECODE, SZONE.ZONENAME " _
                & " FROM " & System.Configuration.ConfigurationSettings.AppSettings("TableSBRANCH") & " INNER JOIN " _
                & "      " & System.Configuration.ConfigurationSettings.AppSettings("TableSDEPARTMENT") & " ON SBRANCH.DEPTCODE = SDEPARTMENT.DEPTCODE " _
                & " INNER Join " _
                & "      " & System.Configuration.ConfigurationSettings.AppSettings("TableSZONE") & " ON SBRANCH.ZONECODE = SZONE.ZONECODE " _
                & StrWhere _
                & " order by deptcode asc,branchcode asc ,zonecode asc "

        Dim ds As New dsAdminMaster
        Dim cls As New clsConnToDbByReport


        cls.rptBranch(re, strSql, ds, colVarParameter)
        re.prmWhere.Value = strPrmCondition
        ReportViewer1.Report = re

    End Sub

    Private Sub userRpt(ByVal strDeptCode As String, ByVal strBranchCode As String, ByVal strUserRight As String, _
                      ByVal strUserName As String, ByVal strEmpName As String, ByVal strEmpLastName As String, _
                      ByVal strIsInactive As String)

        Dim colVarParameter As Collection = New Collection
        Dim StrWhere As String = ""
        Dim strConcat As String = " where "
        Dim clsSessionMenuRight As clsSessionMenuRight

        Dim strPrmCondition As String = ""
        Dim arrDepCode As String() = Nothing
        Dim arrBranchCode As String() = Nothing
        Dim arrUserRightCode As String() = Nothing
        Dim arrIsInactiveCode As String() = Nothing

        Dim re As rptUser = New rptUser

        clsSessionMenuRight = Session("ClsMenuRight")
        If (clsSessionMenuRight.getRoleGroup > 89) Then
            StrWhere = String.Format("{0}{1}tbl_User.USERNAME <> '" & clsSessionMenuRight.getUserName & "'", StrWhere, strConcat)
            strConcat = " And "
        ElseIf (clsSessionMenuRight.getRoleGroup > 79) Then
            StrWhere = String.Format("{0}{1}tbl_User.USERNAME <> '" & clsSessionMenuRight.getUserName & "'", StrWhere, strConcat)
            strConcat = " And "
            StrWhere = String.Format("{0}{1}tbl_User.ROLECODE < '" & clsSessionMenuRight.getRoleGroup & "'", StrWhere, strConcat)
            strConcat = " And "
        ElseIf (clsSessionMenuRight.getRoleGroup > 69) Then
            StrWhere = String.Format("{0}{1}tbl_User.USERNAME <> '" & clsSessionMenuRight.getUserName & "'", StrWhere, strConcat)
            strConcat = " And "
            StrWhere = String.Format("{0}{1}tbl_User.ROLECODE < '" & clsSessionMenuRight.getRoleGroup & "'", StrWhere, strConcat)
            strConcat = " And "
        ElseIf (clsSessionMenuRight.getRoleGroup > 59) Then
            StrWhere = String.Format("{0}{1}tbl_User.USERNAME <> '" & clsSessionMenuRight.getUserName & "'", StrWhere, strConcat)
            strConcat = " And "
            StrWhere = String.Format("{0}{1}tbl_User.ROLECODE < '" & clsSessionMenuRight.getRoleGroup & "' and tbl_User.ZONECODE='" & clsSessionMenuRight.getZoneCode & "'", StrWhere, strConcat)
            strConcat = " And "

        ElseIf (clsSessionMenuRight.getRoleGroup < 60) Then
            StrWhere = String.Format("{0}{1}tbl_User.USERNAME <> '" & clsSessionMenuRight.getUserName & "'", StrWhere, strConcat)
            strConcat = " And "
            '    qryLogLogin = qryLogLogin.Where(Function(fn) fn.ROLECODE < clsSessionMenuRight.getRoleGroup)
            StrWhere = String.Format("{0}{1}tbl_User.ROLECODE < '" & clsSessionMenuRight.getRoleGroup & "'", StrWhere, strConcat)
            strConcat = " And "
        End If


        If Not strDeptCode = "" Then
            arrDepCode = strDeptCode.Split("/")
            If Not arrDepCode(0) = "0" Then
                StrWhere = String.Format("{0}{1}tbl_User.DEPTCODE = :DEPTCODE", StrWhere, strConcat)
                strConcat = " And "

                clsVarParameter = New clsVariable() With {.nameColumn = "DEPTCODE", _
                                                          .valueColumn = arrDepCode(0)}
                colVarParameter.Add(clsVarParameter)

                re.prmDep.Value = arrDepCode(1)
                'If (strPrmCondition = "") Then
                '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtDept, arrDepCode(1))
                'Else
                '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtDept, arrDepCode(1))
                'End If
            Else
                re.prmDep.Value = " ทั้งหมด "
                'If (strPrmCondition = "") Then
                '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtDept, "-")
                'Else
                '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtDept, "-")
                'End If
            End If
        End If

        If Not strBranchCode = "" Then
            arrBranchCode = strBranchCode.Split("/")
            If Not arrBranchCode(0) = "0" Then
                StrWhere = String.Format("{0}{1}tbl_User.BRANCHCODE = :BRANCHCODE", _
                                         StrWhere, _
                                         strConcat)
                strConcat = " And "
                clsVarParameter = New clsVariable() With {.nameColumn = "BRANCHCODE", _
                                                          .valueColumn = arrBranchCode(0)}
                colVarParameter.Add(clsVarParameter)
                re.prmBranch.Value = arrBranchCode(1)
                'If (strPrmCondition = "") Then
                '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtBranch, arrDepCode(1))
                'Else
                '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtBranch, arrDepCode(1))
                'End If
            Else
                re.prmBranch.Value = " ทั้งหมด "
                'If (strPrmCondition = "") Then
                '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtBranch, "-")
                'Else
                '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtBranch, "-")
                'End If
            End If
        End If

        If Not strUserRight = "" Then
            arrUserRightCode = strUserRight.Split("/")
            If Not arrUserRightCode(0) = "0" Then
                StrWhere = String.Format("{0}{1}UserRight.USERRIGHT = :USERRIGHT", _
                                         StrWhere, _
                                         strConcat)
                strConcat = " And "
                clsVarParameter = New clsVariable() With {.nameColumn = "USERRIGHT", _
                                                          .valueColumn = arrUserRightCode(0)}
                colVarParameter.Add(clsVarParameter)
                'If (strPrmCondition = "") Then
                '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtUserRight, arrUserRightCode(1))
                'Else
                '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtUserRight, arrUserRightCode(1))
                'End If
            Else
                'If (strPrmCondition = "") Then
                '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtUserRight, "-")
                'Else
                '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtUserRight, "-")
                'End If
            End If
        End If


        If Not strUserName = "" Then
            If (strUserName.Length < 5) Then

                StrWhere = String.Format("{0}{1}tbl_User.USERNAME like '%' || :USERNAME || '%'", _
                                              StrWhere, _
                                              strConcat)
            Else

                StrWhere = String.Format("{0}{1}tbl_User.USERNAME = :USERNAME", _
                                                   StrWhere, _
                                                   strConcat)
            End If

            strConcat = " And "
            clsVarParameter = New clsVariable() With {.nameColumn = "USERNAME", _
                                                      .valueColumn = strUserName}
            colVarParameter.Add(clsVarParameter)

            'If (strPrmCondition = "") Then
            '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtUserName, strUserName)
            'Else
            '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtUserName, strUserName)
            'End If

        Else
            'If (strPrmCondition = "") Then
            '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtUserName, "-")
            'Else
            '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtUserName, "-")
            'End If
        End If

        If Not strEmpName = "" Then
            StrWhere = String.Format("{0}{1}tbl_User.EMPNAME like '%' || :EMPNAME || '%'", _
                                     StrWhere, _
                                     strConcat)
            strConcat = " And "
            clsVarParameter = New clsVariable() With {.nameColumn = "EMPNAME", _
                                                      .valueColumn = strEmpName}
            colVarParameter.Add(clsVarParameter)
            'If (strPrmCondition = "") Then
            '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtEmpName, strEmpName)
            'Else
            '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtEmpName, strEmpName)
            'End If

        Else
            'If (strPrmCondition = "") Then
            '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtEmpName, "-")
            'Else
            '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtEmpName, "-")
            'End If
        End If

        If Not strEmpLastName = "" Then
            StrWhere = String.Format("{0}{1}tbl_User.EMPLASTNAME like '%' || :EMPLASTNAME || '%'", _
                                     StrWhere, _
                                     strConcat)
            strConcat = " And "
            clsVarParameter = New clsVariable() With {.nameColumn = "EMPLASTNAME", _
                                                      .valueColumn = strEmpLastName}
            colVarParameter.Add(clsVarParameter)
            'If (strPrmCondition = "") Then
            '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtLastName, strEmpLastName)
            'Else
            '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtLastName, strEmpLastName)
            'End If

        Else
            'If (strPrmCondition = "") Then
            '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtLastName, "-")
            'Else
            '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtLastName, "-")
            'End If
        End If


        If Not strIsInactive = "" Then
            arrIsInactiveCode = strIsInactive.Split("/")
            If Not arrIsInactiveCode(0) = "-1" Then
                StrWhere = String.Format("{0}{1}tbl_User.ISINACTIVE = :ISINACTIVE ", _
                                     StrWhere, _
                                     strConcat)
                strConcat = " And "
                clsVarParameter = New clsVariable() With {.nameColumn = "ISINACTIVE", _
                                                          .valueColumn = arrIsInactiveCode(0)}
                colVarParameter.Add(clsVarParameter)

                'If (strPrmCondition = "") Then
                '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtUserRightStatus, arrIsInactiveCode(1))
                'Else
                '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtUserRightStatus, arrIsInactiveCode(1))
                'End If
            Else
                'If (strPrmCondition = "") Then
                '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtUserRightStatus, "-")
                'Else
                '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtUserRightStatus, "-")
                'End If
            End If
        End If



        strSql = "Select tbl_User.USERNAME, tbl_User.EMPCODE, tbl_Branch.BRANCHNAME, tbl_User.BRANCHCODE, " _
                & "      tbl_User.DEPTCODE, tbl_Dept.DEPTNAME, tbl_User.ROLECODE, tbl_User.PWDBEGINDATE, " _
                & "      tbl_User.MUSTCHANGEPWD, UserRight.USERRIGHT, UserRight.USERRIGHTDESC, " _
                & "      tbl_User.INACTIVEDATE, tbl_User.ISINACTIVE,  tbl_User.EMPNAME, " _
                & "      tbl_User.EMPLASTNAME, tbl_role.ROLENAME, tbl_User.ZONECODE " _
                & " From  " & System.Configuration.ConfigurationSettings.AppSettings("TableSUSER") & " tbl_User " _
                & "              Join " & System.Configuration.ConfigurationSettings.AppSettings("TableSBRANCH") & " tbl_Branch  On tbl_User.BRANCHCODE = tbl_Branch.BRANCHCODE " _
                & "              Join " & System.Configuration.ConfigurationSettings.AppSettings("TableSDEPARTMENT") & " tbl_Dept On tbl_User.DEPTCODE = tbl_Dept.DEPTCODE " _
                & "              Join " & System.Configuration.ConfigurationSettings.AppSettings("TableSUSERRIGHT") & " userRight On tbl_User.USERRIGHT = userRight.USERRIGHT " _
                & "              Join " & System.Configuration.ConfigurationSettings.AppSettings("TableSROLE") & " tbl_role On tbl_User.ROLECODE = tbl_role.ROLECODE" _
                & StrWhere _
                & " Order By tbl_User.USERNAME "

        Dim ds As New dsAdminMaster
        Dim cls As New clsConnToDbByReport


        cls.rptUser(re, strSql, ds, colVarParameter)
        re.prmWhere.Value = strPrmCondition
        ReportViewer1.Report = re


    End Sub

    Private Sub unlockUserRpt(ByVal strDeptCode As String, ByVal strBranchCode As String, ByVal strUserRight As String, _
                      ByVal strUserName As String, ByVal strEmpName As String, ByVal strEmpLastName As String, _
                      ByVal strLockType As String, ByVal strStartDate As String, ByVal strEndDate As String)

        Dim colVarParameter As Collection = New Collection
        Dim StrWhere As String = ""
        Dim strConcat As String = " where "
        Dim clsSessionMenuRight As clsSessionMenuRight
        Dim clsFormatDate As New clsDateFormat

        Dim strPrmCondition As String = ""
        Dim arrDepCode As String() = Nothing
        Dim arrBranchCode As String() = Nothing
        Dim arrUserRightCode As String() = Nothing
        Dim arrLockTypeCode As String() = Nothing

        Dim re As rptUnlockUser = New rptUnlockUser

        clsSessionMenuRight = Session("ClsMenuRight")
        If (clsSessionMenuRight.getRoleGroup > 89) Then
            StrWhere = String.Format("{0}{1}tbl_User.USERNAME <> '" & clsSessionMenuRight.getUserName & "'", StrWhere, strConcat)
            strConcat = " And "
        ElseIf (clsSessionMenuRight.getRoleGroup > 79) Then
            StrWhere = String.Format("{0}{1}tbl_User.USERNAME <> '" & clsSessionMenuRight.getUserName & "'", StrWhere, strConcat)
            strConcat = " And "
            StrWhere = String.Format("{0}{1}tbl_User.ROLECODE < '" & clsSessionMenuRight.getRoleGroup & "'", StrWhere, strConcat)
            strConcat = " And "
        ElseIf (clsSessionMenuRight.getRoleGroup > 69) Then
            StrWhere = String.Format("{0}{1}tbl_User.USERNAME <> '" & clsSessionMenuRight.getUserName & "'", StrWhere, strConcat)
            strConcat = " And "
            StrWhere = String.Format("{0}{1}tbl_User.ROLECODE < '" & clsSessionMenuRight.getRoleGroup & "'", StrWhere, strConcat)
            strConcat = " And "
        ElseIf (clsSessionMenuRight.getRoleGroup > 59) Then
            StrWhere = String.Format("{0}{1}tbl_User.USERNAME <> '" & clsSessionMenuRight.getUserName & "'", StrWhere, strConcat)
            strConcat = " And "
            StrWhere = String.Format("{0}{1}tbl_User.ROLECODE < '" & clsSessionMenuRight.getRoleGroup & "' and tbl_User.ZONECODE='" & clsSessionMenuRight.getZoneCode & "'", StrWhere, strConcat)
            strConcat = " And "

        ElseIf (clsSessionMenuRight.getRoleGroup < 60) Then
            StrWhere = String.Format("{0}{1}tbl_User.USERNAME <> '" & clsSessionMenuRight.getUserName & "'", StrWhere, strConcat)
            strConcat = " And "
            '    qryLogLogin = qryLogLogin.Where(Function(fn) fn.ROLECODE < clsSessionMenuRight.getRoleGroup)
            StrWhere = String.Format("{0}{1}tbl_User.ROLECODE < '" & clsSessionMenuRight.getRoleGroup & "'", StrWhere, strConcat)
            strConcat = " And "
        End If


        If Not strDeptCode = "" Then
            arrDepCode = strDeptCode.Split("/")
            If Not arrDepCode(0) = "0" Then
                StrWhere = String.Format("{0}{1}tbl_User.DEPTCODE = :DEPTCODE", StrWhere, strConcat)
                strConcat = " And "

                clsVarParameter = New clsVariable() With {.nameColumn = "DEPTCODE", _
                                                          .valueColumn = arrDepCode(0)}
                colVarParameter.Add(clsVarParameter)

                re.prmDep.Value = arrDepCode(1)
                'If (strPrmCondition = "") Then
                '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtDept, arrDepCode(1))
                'Else
                '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtDept, arrDepCode(1))
                'End If
            Else
                re.prmDep.Value = " ทั้งหมด "
                'If (strPrmCondition = "") Then
                '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtDept, "-")
                'Else
                '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtDept, "-")
                'End If
            End If
        End If

        If Not strBranchCode = "" Then
            arrBranchCode = strBranchCode.Split("/")
            If Not arrBranchCode(0) = "0" Then
                StrWhere = String.Format("{0}{1}tbl_User.BRANCHCODE = :BRANCHCODE", _
                                         StrWhere, _
                                         strConcat)
                strConcat = " And "
                clsVarParameter = New clsVariable() With {.nameColumn = "BRANCHCODE", _
                                                          .valueColumn = arrBranchCode(0)}
                colVarParameter.Add(clsVarParameter)
                re.prmBranch.Value = arrBranchCode(1)
                'If (strPrmCondition = "") Then
                '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtBranch, arrDepCode(1))
                'Else
                '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtBranch, arrDepCode(1))
                'End If
            Else
                re.prmBranch.Value = " ทั้งหมด "
                'If (strPrmCondition = "") Then
                '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtBranch, "-")
                'Else
                '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtBranch, "-")
                'End If
            End If
        End If

        If Not strUserRight = "" Then
            arrUserRightCode = strUserRight.Split("/")
            If Not arrUserRightCode(0) = "0" Then
                StrWhere = String.Format("{0}{1}UserRight.USERRIGHT = :USERRIGHT", _
                                         StrWhere, _
                                         strConcat)
                strConcat = " And "
                clsVarParameter = New clsVariable() With {.nameColumn = "USERRIGHT", _
                                                          .valueColumn = arrUserRightCode(0)}
                colVarParameter.Add(clsVarParameter)
                'If (strPrmCondition = "") Then
                '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtUserRight, arrUserRightCode(1))
                'Else
                '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtUserRight, arrUserRightCode(1))
                'End If
            Else
                'If (strPrmCondition = "") Then
                '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtUserRight, "-")
                'Else
                '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtUserRight, "-")
                'End If
            End If
        End If


        If Not strUserName = "" Then
            If (strUserName.Length < 5) Then

                StrWhere = String.Format("{0}{1}tbl_User.USERNAME like '%' || :USERNAME || '%'", _
                                              StrWhere, _
                                              strConcat)
            Else

                StrWhere = String.Format("{0}{1}tbl_User.USERNAME = :USERNAME", _
                                                   StrWhere, _
                                                   strConcat)
            End If

            strConcat = " And "
            clsVarParameter = New clsVariable() With {.nameColumn = "USERNAME", _
                                                      .valueColumn = strUserName}
            colVarParameter.Add(clsVarParameter)

            'If (strPrmCondition = "") Then
            '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtUserName, strUserName)
            'Else
            '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtUserName, strUserName)
            'End If

        Else
            'If (strPrmCondition = "") Then
            '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtUserName, "-")
            'Else
            '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtUserName, "-")
            'End If
        End If

        If Not strEmpName = "" Then
            StrWhere = String.Format("{0}{1}tbl_User.EMPNAME like '%' || :EMPNAME || '%'", _
                                     StrWhere, _
                                     strConcat)
            strConcat = " And "
            clsVarParameter = New clsVariable() With {.nameColumn = "EMPNAME", _
                                                      .valueColumn = strEmpName}
            colVarParameter.Add(clsVarParameter)
            'If (strPrmCondition = "") Then
            '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtEmpName, strEmpName)
            'Else
            '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtEmpName, strEmpName)
            'End If

        Else
            'If (strPrmCondition = "") Then
            '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtEmpName, "-")
            'Else
            '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtEmpName, "-")
            'End If
        End If

        If Not strEmpLastName = "" Then
            StrWhere = String.Format("{0}{1}tbl_User.EMPLASTNAME like '%' || :EMPLASTNAME || '%'", _
                                     StrWhere, _
                                     strConcat)
            strConcat = " And "
            clsVarParameter = New clsVariable() With {.nameColumn = "EMPLASTNAME", _
                                                      .valueColumn = strEmpLastName}
            colVarParameter.Add(clsVarParameter)
            'If (strPrmCondition = "") Then
            '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtLastName, strEmpLastName)
            'Else
            '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtLastName, strEmpLastName)
            'End If

        Else
            'If (strPrmCondition = "") Then
            '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtLastName, "-")
            'Else
            '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtLastName, "-")
            'End If
        End If


        If Not strLockType = "" Then
            arrLockTypeCode = strLockType.Split("/")
            If Not arrLockTypeCode(0) = "0" Then
                StrWhere = String.Format("{0}{1}hist.REASONCODE = :REASONCODE ", _
                                     StrWhere, _
                                     strConcat)
                strConcat = " And "
                clsVarParameter = New clsVariable() With {.nameColumn = "REASONCODE", _
                                                          .valueColumn = arrLockTypeCode(0)}
                colVarParameter.Add(clsVarParameter)

            Else
                'If (strPrmCondition = "") Then
                '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtUserRightStatus, "-")
                'Else
                '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtUserRightStatus, "-")
                'End If
            End If
        End If

        If Not (strStartDate = "" And strEndDate = "") Then
            Dim dteStartDate As Date = clsFormatDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.En, strStartDate) & " 00:00:00"
            Dim dteEndDate As Date = clsFormatDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.En, strEndDate) & " 23:59:59"
            StrWhere = String.Format("{0}{1}hist.DATEUNLOCK >= :StartDate and hist.DATEUNLOCK <= :EndDate", _
                                     StrWhere, _
                                     strConcat)
            strConcat = " And "
            clsVarParameter = New clsVariable() With {.nameColumn = "StartDate", _
                                                      .valueColumn = dteStartDate}
            colVarParameter.Add(clsVarParameter)

            clsVarParameter = New clsVariable() With {.nameColumn = "EndDate", _
                                                      .valueColumn = dteEndDate}
            colVarParameter.Add(clsVarParameter)
            
            're.prmStartDate.Value = strStartDate
            're.prmEndDate.Value = strEndDate
        Else
            're.prmStartDate.Value = " - "
            're.prmEndDate.Value = " - "
        End If


        strSql = "Select tbl_User.USERNAME, tbl_User.EMPCODE, tbl_Branch.BRANCHNAME, tbl_User.BRANCHCODE, " _
                & "      tbl_User.DEPTCODE, tbl_Dept.DEPTNAME, tbl_User.ROLECODE, tbl_User.PWDBEGINDATE, " _
                & "      tbl_User.MUSTCHANGEPWD, UserRight.USERRIGHT, UserRight.USERRIGHTDESC, " _
                & "      tbl_User.INACTIVEDATE, tbl_User.ISINACTIVE,  tbl_User.EMPNAME, " _
                & "      tbl_User.EMPLASTNAME, tbl_role.ROLENAME, tbl_User.ZONECODE, " _
                & "      hist.USERNAMEUNLOCK as UNLOCKER, hist.DATEUNLOCK, hist.REASONCODE, hist.REASONTXT " _
                & " From  " & System.Configuration.ConfigurationSettings.AppSettings("TableH_UNLOCKUSER") & " hist " _
                & "              Join " & System.Configuration.ConfigurationSettings.AppSettings("TableSUSER") & " tbl_User On hist.USERNAMELOCK = tbl_User.USERNAME " _
                & "              Join " & System.Configuration.ConfigurationSettings.AppSettings("TableSBRANCH") & " tbl_Branch  On tbl_User.BRANCHCODE = tbl_Branch.BRANCHCODE " _
                & "              Join " & System.Configuration.ConfigurationSettings.AppSettings("TableSDEPARTMENT") & " tbl_Dept On tbl_User.DEPTCODE = tbl_Dept.DEPTCODE " _
                & "              Join " & System.Configuration.ConfigurationSettings.AppSettings("TableSUSERRIGHT") & " userRight On tbl_User.USERRIGHT = userRight.USERRIGHT " _
                & "              Join " & System.Configuration.ConfigurationSettings.AppSettings("TableSROLE") & " tbl_role On tbl_User.ROLECODE = tbl_role.ROLECODE" _
                & StrWhere _
                & " Order By tbl_User.USERNAME "

        Dim ds As New dsAdminMaster
        Dim cls As New clsConnToDbByReport


        cls.rptUnlockUser(re, strSql, ds, colVarParameter)
        re.prmWhere.Value = strPrmCondition
        ReportViewer1.Report = re


    End Sub

    Private Sub HistoryLoginrpt(ByVal strDeptCode As String, ByVal strBranchCode As String, _
                             ByVal strUserRight As String, ByVal strUserName As String, _
                             ByVal strEmpName As String, ByVal strEmpLastName As String, _
                             ByVal strStartDate As String, ByVal strEndDate As String, _
                             ByVal intLoginPass As String, ByVal intLogOut As String, _
                             ByVal intLoginFalse As String)

        Dim colVarParameter As Collection = New Collection
        Dim StrWhere As String = ""
        Dim strConcat As String = " where "
        Dim clsFormatDate As New clsDateFormat
        Dim clsSessionMenuRight As clsSessionMenuRight
        Dim strPrmCondition As String = ""
        Dim arrDepCode As String() = Nothing
        Dim arrBranchCode As String() = Nothing
        Dim arrUserRightCode As String() = Nothing
        Dim arrStatus As String() = Nothing

        Dim re As rptLoginLog = New rptLoginLog

        clsSessionMenuRight = Session("ClsMenuRight")




        If (clsSessionMenuRight.getRoleGroup > 89) Then
            StrWhere = String.Format("{0}{1}LogLogin.ROLECODE <= '" & clsSessionMenuRight.getRoleGroup & "'", StrWhere, strConcat)
            strConcat = " And "
        ElseIf (clsSessionMenuRight.getRoleGroup > 79) Then
            StrWhere = String.Format("{0}{1}LogLogin.ROLECODE <= '" & clsSessionMenuRight.getRoleGroup & "'", StrWhere, strConcat)
            strConcat = " And "
        ElseIf (clsSessionMenuRight.getRoleGroup > 69) Then
            StrWhere = String.Format("{0}{1}LogLogin.ROLECODE <= '" & clsSessionMenuRight.getRoleGroup & "'", StrWhere, strConcat)
            strConcat = " And "
        ElseIf (clsSessionMenuRight.getRoleGroup > 59) Then
            StrWhere = String.Format("{0}{1}LogLogin.ROLECODE <= '" & clsSessionMenuRight.getRoleGroup & "' and LogLogin.ZONECODE='" & clsSessionMenuRight.getZoneCode & "'", StrWhere, strConcat)
            strConcat = " And "

        ElseIf (clsSessionMenuRight.getRoleGroup < 60) Then
            '    qryLogLogin = qryLogLogin.Where(Function(fn) fn.ROLECODE < clsSessionMenuRight.getRoleGroup)
            StrWhere = String.Format("{0}{1}LogLogin.ROLECODE < '" & clsSessionMenuRight.getRoleGroup & "'", StrWhere, strConcat)
            strConcat = " And "
        End If

        If Not strDeptCode = "" Then
            arrDepCode = strDeptCode.Split("/")
            If Not arrDepCode(0) = "0" Then
                StrWhere = String.Format("{0}{1}LogLogin.DEPTCODE = :DEPTCODE", StrWhere, strConcat)
                strConcat = " And "

                clsVarParameter = New clsVariable() With {.nameColumn = "DEPTCODE", _
                                                          .valueColumn = arrDepCode(0)}
                colVarParameter.Add(clsVarParameter)
                'If (strPrmCondition = "") Then
                '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtDept, arrDepCode(1))
                'Else
                '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtDept, arrDepCode(1))
                'End If
                re.prmDep.Value = arrDepCode(1)
            Else
                re.prmDep.Value = " ทั้งหมด "
                'If (strPrmCondition = "") Then
                '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtDept, "-")
                'Else
                '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtDept, "-")
                'End If
            End If
        End If

        If Not strBranchCode = "" Then
            arrBranchCode = strBranchCode.Split("/")
            If Not arrBranchCode(0) = "0" Then
                StrWhere = String.Format("{0}{1}LogLogin.BRANCHCODE = :BRANCHCODE", _
                                         StrWhere, _
                                         strConcat)
                strConcat = " And "
                clsVarParameter = New clsVariable() With {.nameColumn = "BRANCHCODE", _
                                                          .valueColumn = arrBranchCode(0)}
                colVarParameter.Add(clsVarParameter)
                re.prmBranch.Value = arrBranchCode(1)
                'If (strPrmCondition = "") Then
                '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtBranch, arrDepCode(1))
                'Else
                '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtBranch, arrDepCode(1))
                'End If
            Else
                re.prmBranch.Value = " ทั้งหมด "
                'If (strPrmCondition = "") Then
                '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtBranch, "-")
                'Else
                '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtBranch, "-")
                'End If
            End If
        End If

        If Not strUserRight = "" Then
            arrUserRightCode = strUserRight.Split("/")
            If Not arrUserRightCode(0) = "0" Then
                StrWhere = String.Format("{0}{1}LogLogin.USERRIGHT = :USERRIGHT", _
                                         StrWhere, _
                                         strConcat)
                strConcat = " And "
                clsVarParameter = New clsVariable() With {.nameColumn = "USERRIGHT", _
                                                          .valueColumn = arrUserRightCode(0)}
                colVarParameter.Add(clsVarParameter)
                re.prmUserRight.Value = arrUserRightCode(1)
                'If (strPrmCondition = "") Then
                '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtUserRight, arrUserRightCode(1))
                'Else
                '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtUserRight, arrUserRightCode(1))
                'End If
            Else
                re.prmUserRight.Value = arrUserRightCode(1)
                'If (strPrmCondition = "") Then
                '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtUserRight, "-")
                'Else
                '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtUserRight, "-")
                'End If
            End If
        End If

        If Not strUserName = "" Then
            If (strUserName.Length < 5) Then

                StrWhere = String.Format("{0}{1}LogLogin.USERNAME like '%' || :USERNAME || '%'", _
                                              StrWhere, _
                                              strConcat)
            Else

                StrWhere = String.Format("{0}{1}LogLogin.USERNAME = :USERNAME", _
                                                   StrWhere, _
                                                   strConcat)
            End If

            strConcat = " And "
            clsVarParameter = New clsVariable() With {.nameColumn = "USERNAME", _
                                                      .valueColumn = strUserName}
            colVarParameter.Add(clsVarParameter)
            'If (strPrmCondition = "") Then
            '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtUserName, strUserName)
            'Else
            '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtUserName, strUserName)
            'End If
            re.prmUserName.Value = strUserName
        Else
            re.prmUserName.Value = " - "
            'If (strPrmCondition = "") Then
            '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtUserName, "-")
            'Else
            '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtUserName, "-")
            'End If
        End If

        If Not strEmpName = "" Then
            StrWhere = String.Format("{0}{1}LogLogin.EMPNAME like '%' || :EMPNAME || '%'", _
                                     StrWhere, _
                                     strConcat)
            strConcat = " And "
            clsVarParameter = New clsVariable() With {.nameColumn = "EMPNAME", _
                                                      .valueColumn = strEmpName}
            colVarParameter.Add(clsVarParameter)
            'If (strPrmCondition = "") Then
            '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtEmpName, strEmpName)
            'Else
            '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtEmpName, strEmpName)
            'End If
            re.prmName.Value = strEmpName
        Else
            re.prmName.Value = " - "
            'If (strPrmCondition = "") Then
            '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtEmpName, "-")
            'Else
            '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtEmpName, "-")
            'End If
        End If

        If Not strEmpLastName = "" Then
            StrWhere = String.Format("{0}{1}LogLogin.EMPLASTNAME like '%' || :EMPLASTNAME || '%'", _
                                     StrWhere, _
                                     strConcat)
            strConcat = " And "
            clsVarParameter = New clsVariable() With {.nameColumn = "EMPLASTNAME", _
                                                      .valueColumn = strEmpLastName}
            colVarParameter.Add(clsVarParameter)
            re.prmLastName.Value = strEmpLastName
            'If (strPrmCondition = "") Then
            '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtLastName, strEmpLastName)
            'Else
            '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtLastName, strEmpLastName)
            'End If

        Else
            re.prmLastName.Value = " - "
            'If (strPrmCondition = "") Then
            '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtLastName, "-")
            'Else
            '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtLastName, "-")
            'End If
        End If

        If Not (strStartDate = "" And strEndDate = "") Then
            Dim dteStartDate As Date = clsFormatDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.En, strStartDate) & " 00:00:00"
            Dim dteEndDate As Date = clsFormatDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.En, strEndDate) & " 23:59:59"
            StrWhere = String.Format("{0}{1}LogLogin.LOGINDATE >= :StartDate and LogLogin.LOGINDATE <= :EndDate", _
                                     StrWhere, _
                                     strConcat)
            strConcat = " And "
            clsVarParameter = New clsVariable() With {.nameColumn = "StartDate", _
                                                      .valueColumn = dteStartDate}
            colVarParameter.Add(clsVarParameter)

            clsVarParameter = New clsVariable() With {.nameColumn = "EndDate", _
                                                      .valueColumn = dteEndDate}
            colVarParameter.Add(clsVarParameter)
            'If (strPrmCondition = "") Then
            '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtDate, dteStartDate & "   ถึง   " & dteEndDate)
            'Else
            '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtDate, dteStartDate & "   ถึง   " & dteEndDate)
            'End If
            re.prmStartDate.Value = strStartDate
            re.prmEndDate.Value = strEndDate
        Else
            re.prmStartDate.Value = " - "
            re.prmEndDate.Value = " - "
            'If (strPrmCondition = "") Then
            '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtDate, "-")
            'Else
            '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtDate, "-")
            'End If
        End If
        '-------------------------------------------------------------------------------

        Dim strTempStatus As String = ""
        Dim intTempLoginPass As Integer = 0
        Dim intTempLogOut As Integer = 0
        Dim intTempLoginFalse As Integer = 0

        If Not (intLoginPass.Split("/")(0) = -1 And intLogOut.Split("/")(0) = -1 And intLoginFalse.Split("/")(0) = -1) Then
            If Not strConcat = " where " Then
                StrWhere += " And ( "
            Else
                StrWhere += " ( "
            End If

        End If

        If Not intLoginPass = "" Then
            arrStatus = Nothing
            arrStatus = intLoginPass.Split("/")
            intTempLoginPass = arrStatus(0)
            If arrStatus(0) = "1" Then
                If strConcat = " And " Then
                    StrWhere = String.Format("{0}LogLogin.LOGINTYPE = :LoginPass", _
                                       StrWhere)
                Else
                    StrWhere = String.Format("{0}{1}LogLogin.LOGINTYPE = :LoginPass", _
                                                       StrWhere, _
                                                       strConcat)
                End If

                strConcat = " or "
                clsVarParameter = New clsVariable() With {.nameColumn = "LoginPass", _
                                                          .valueColumn = arrStatus(0)}
                colVarParameter.Add(clsVarParameter)
                If (strTempStatus = "") Then
                    strTempStatus = arrStatus(1)
                Else
                    strTempStatus = strTempStatus & " , " & arrStatus(1)
                End If
            End If
        End If


        If Not intLogOut = "" Then
            arrStatus = Nothing
            arrStatus = intLogOut.Split("/")
            intTempLogOut = arrStatus(0)
            If arrStatus(0) = "0" Then

                If strConcat = " And " Then
                    StrWhere = String.Format("{0}LogLogin.LOGINTYPE = :LogOut", _
                                                       StrWhere)
                Else
                    StrWhere = String.Format("{0}{1}LogLogin.LOGINTYPE = :LogOut", _
                                           StrWhere, _
                                           strConcat)

                End If

                strConcat = " or "
                clsVarParameter = New clsVariable() With {.nameColumn = "LogOut", _
                                                          .valueColumn = arrStatus(0)}
                colVarParameter.Add(clsVarParameter)
                If (strTempStatus = "") Then
                    strTempStatus = arrStatus(1)
                Else
                    strTempStatus = strTempStatus & " , " & arrStatus(1)
                End If
            End If
        End If

        If Not intLoginFalse = "" Then
            arrStatus = Nothing
            arrStatus = intLoginFalse.Split("/")
            intTempLoginFalse = arrStatus(0)
            If arrStatus(0) = "2" Then
                If strConcat = " And " Then
                    StrWhere = String.Format("{0}LogLogin.LOGINTYPE = :LoginFalse", _
                                                       StrWhere)
                Else
                    StrWhere = String.Format("{0}{1}LogLogin.LOGINTYPE = :LoginFalse", _
                                                       StrWhere, _
                                                       strConcat)
                End If

                strConcat = " or "
                clsVarParameter = New clsVariable() With {.nameColumn = "LoginFalse", _
                                                          .valueColumn = arrStatus(0)}
                colVarParameter.Add(clsVarParameter)
                If (strTempStatus = "") Then
                    strTempStatus = arrStatus(1)
                Else
                    strTempStatus = strTempStatus & " , " & arrStatus(1)
                End If
            End If
        End If


        If Not strTempStatus = "" Then
            re.prmType.Value = strTempStatus
        Else
            re.prmType.Value = " - "
        End If


        If (intTempLoginPass = -1 And intTempLogOut = -1 And intTempLoginFalse = -1) Then
            StrWhere = String.Format("{0}{1}LogLogin.LOGINTYPE = 10", _
                                StrWhere, _
                                strConcat)
            If (strPrmCondition = "") Then
                strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtUserRightStatus, "-")
            Else
                strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtUserRightStatus, "-")
            End If
        Else
            If (strPrmCondition = "") Then
                strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtUserRightStatus, strTempStatus)
            Else
                strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtUserRightStatus, strTempStatus)
            End If

            StrWhere += " ) "
        End If
        '------------------------------------------------------------------------------

        strSql = "Select LogLogin.USERNAME, LogLogin.EMPNAME, LogLogin.EMPLASTNAME, LogLogin.ROLECODE, LogLogin.DEPTCODE, " _
                 & "     LogLogin.ZONECODE, LogLogin.BRANCHCODE, LogLogin.LASTIP, LogLogin.USERRIGHT, LogLogin.LOGINDATE, " _
                 & "     LogLogin.LOGINTYPE " _
                 & " From  " & System.Configuration.ConfigurationSettings.AppSettings("TableSLOGINLOG") & " LogLogin " _
                 & StrWhere _
                 & "  Order By LogLogin.LOGINDATE Desc "

        Dim ds As New dsAdminMaster
        Dim cls As New clsConnToDbByReport


        cls.rptLoginlog(re, strSql, ds, colVarParameter)
        re.prmWhere.Value = strPrmCondition
        ReportViewer1.Report = re

    End Sub

#End Region

#Region " RptMaster "

#Region "Master Amlo"

    Private Sub MTSCTYPE1(ByVal strTypeTscId As String, ByVal strTypeTscName As String)

        Dim colVarParameter As Collection = New Collection
        Dim StrWhere As String = ""
        Dim strConcat As String = " where "


        If Not strTypeTscId = "" Then
            StrWhere = String.Format("{0}{1}TYPE_TSC_ID like '%' || :TYPETSCID || '%'", StrWhere, strConcat)
            strConcat = " And "

            clsVarParameter = New clsVariable() With {.nameColumn = "TYPETSCID", _
                                                      .valueColumn = strTypeTscId}
            colVarParameter.Add(clsVarParameter)
        End If

        If Not strTypeTscName = "" Then
            StrWhere = String.Format("{0}{1}TYPE_TSC_NAME like '%' || :TYPETSCNAME || '%'", _
                                     StrWhere, _
                                     strConcat)
            strConcat = " And "
            clsVarParameter = New clsVariable() With {.nameColumn = "TYPETSCNAME", _
                                                      .valueColumn = strTypeTscName}
            colVarParameter.Add(clsVarParameter)
        End If

        strSql = "   SELECT     TYPE_TSC_ID , TYPE_TSC_NAME, SHOWINDEX " _
                      & "  FROM " & System.Configuration.ConfigurationSettings.AppSettings("TableMTSCTYPE1") & "  order by TYPE_TSC_ID"

        Dim ds As New dsMasterAmlo
        Dim cls As New clsConnToDbByReport
        Dim re As rptMTSCTYPE1 = New rptMTSCTYPE1

        cls.rptMTscType1(re, strSql, ds, colVarParameter)
        ReportViewer1.Report = re
    End Sub

    Private Sub MOBJTYPE(ByVal strObjTypeId As String, ByVal strObjTypeName As String)
        Dim colVarParameter As Collection = New Collection
        Dim StrWhere As String = ""
        Dim strConcat As String = " where "


        If Not strObjTypeId = "" Then
            StrWhere = String.Format("{0}{1}OBJTYPEID like '%' || :OBJTYPEID || '%'", StrWhere, strConcat)
            strConcat = " And "

            clsVarParameter = New clsVariable() With {.nameColumn = "OBJTYPEID", _
                                                      .valueColumn = strObjTypeId}
            colVarParameter.Add(clsVarParameter)
        End If

        If Not strObjTypeName = "" Then
            StrWhere = String.Format("{0}{1}OBJTYPENAME like '%' || :OBJTYPENAME || '%'", _
                                     StrWhere, _
                                     strConcat)
            strConcat = " And "
            clsVarParameter = New clsVariable() With {.nameColumn = "OBJTYPENAME", _
                                                      .valueColumn = strObjTypeName}
            colVarParameter.Add(clsVarParameter)
        End If

        strSql = "   SELECT     MOBJTYPE.*" _
                & "  FROM " & System.Configuration.ConfigurationSettings.AppSettings("TableMOBJTYPE") & " order by OBJTYPEID "

        Dim ds As New dsMasterAmlo
        Dim cls As New clsConnToDbByReport
        Dim re As rptMOBJTYPE = New rptMOBJTYPE

        cls.rptMObjType(re, strSql, ds, colVarParameter)
        ReportViewer1.Report = re
    End Sub

    Private Sub TYPE_ID(ByVal strTypeId As String, ByVal strTypeName As String)
        Dim colVarParameter As Collection = New Collection
        Dim StrWhere As String = ""
        Dim strConcat As String = " where "


        If Not strTypeId = "" Then
            StrWhere = String.Format("{0}{1}TYPE_ID like '%' || :TYPEID || '%'", StrWhere, strConcat)
            strConcat = " And "

            clsVarParameter = New clsVariable() With {.nameColumn = "TYPEID", _
                                                      .valueColumn = strTypeId}
            colVarParameter.Add(clsVarParameter)
        End If

        If Not strTypeName = "" Then
            StrWhere = String.Format("{0}{1}TYPE_NAME like '%' || :TYPENAME || '%'", _
                                     StrWhere, _
                                     strConcat)
            strConcat = " And "
            clsVarParameter = New clsVariable() With {.nameColumn = "TYPENAME", _
                                                      .valueColumn = strTypeName}
            colVarParameter.Add(clsVarParameter)
        End If

        strSql = "   SELECT      TYPE_ID TYPEID1, TYPE_NAME, TYPE_WIDTH " _
                & "  FROM " & System.Configuration.ConfigurationSettings.AppSettings("TableTYPE_ID") & " order by TYPE_ID "

        Dim ds As New dsMasterAmlo
        Dim cls As New clsConnToDbByReport
        ' Dim re As rptTYPE_ID = New rptTYPE_ID
        Dim re As rptTYPE_ID = New rptTYPE_ID
        cls.rptType_Id(re, strSql, ds, colVarParameter)
        'cls.rptType_Id(re, strSql, ds)

        ReportViewer1.Report = re

    End Sub

    Sub MPSNRELATION()

        strSql = "   SELECT     MPSNRELATION.* " _
                & "  FROM " & System.Configuration.ConfigurationSettings.AppSettings("TableMPSNRELATION") & " order by  to_number(PSNRELATIONID) "

        Dim ds As New dsMasterAmlo
        Dim cls As New clsConnToDbByReport
        Dim re As rptMPSNRELATION = New rptMPSNRELATION

        cls.rptMPsnRelation(re, strSql, ds)
        ReportViewer1.Report = re

    End Sub

    Sub MOFFICETYPE()

        strSql = "   SELECT     MOFFICETYPE.*" _
                & "  FROM " & System.Configuration.ConfigurationSettings.AppSettings("TableMOFFICETYPE") & " order by OFFICETYPEID "

        Dim ds As New dsMasterAmlo
        Dim cls As New clsConnToDbByReport
        Dim re As rptMOFFICETYPE = New rptMOFFICETYPE

        cls.rptMOfficeType(re, strSql, ds)
        ReportViewer1.Report = re


    End Sub

    Sub MOFFICEOCC()
        strSql = "   SELECT     MOFFICEOCC.*" _
                & "  FROM " & System.Configuration.ConfigurationSettings.AppSettings("TableMOFFICEOCC") & " order by OFFICEOCCID "

        Dim ds As New dsMasterAmlo
        Dim cls As New clsConnToDbByReport
        Dim re As rptMOFFICEOCC = New rptMOFFICEOCC

        cls.rptMOfficeOcc(re, strSql, ds)
        ReportViewer1.Report = re
    End Sub

    Sub MASSETTYPE()
        strSql = "   SELECT     MASSETTYPE.*" _
               & "  FROM " & System.Configuration.ConfigurationSettings.AppSettings("TableMASSETTYPE") & "  order by ASSETTYPEID "

        Dim ds As New dsMasterAmlo
        Dim cls As New clsConnToDbByReport
        Dim re As rptMASSETTYPE = New rptMASSETTYPE

        cls.rptMAssetType(re, strSql, ds)
        ReportViewer1.Report = re



    End Sub

    Sub MRELATION()

        strSql = "   SELECT     MRELATION.*" _
                & "  FROM " & System.Configuration.ConfigurationSettings.AppSettings("TableMRELATION") & " order by RELATIONID "

        Dim ds As New dsMasterAmlo
        Dim cls As New clsConnToDbByReport
        Dim re As rptMRELATION = New rptMRELATION

        cls.rptMRelation(re, strSql, ds)
        ReportViewer1.Report = re

    End Sub

    Sub MTSCTYPE2()
        strSql = "   SELECT     MTSCTYPE2.*" _
                 & "  FROM " & System.Configuration.ConfigurationSettings.AppSettings("TableMTSCTYPE2") & " order by TSCTYPEID "

        Dim ds As New dsMasterAmlo
        Dim cls As New clsConnToDbByReport
        Dim re As rptMTSCTYPE2 = New rptMTSCTYPE2

        cls.rptMTscType2(re, strSql, ds)
        ReportViewer1.Report = re
    End Sub

    Sub MTSCTYPE3()
        strSql = "   SELECT     MTSCTYPE3.*" _
               & "  FROM " & System.Configuration.ConfigurationSettings.AppSettings("TableMTSCTYPE3") & " order by TSCTYPEID "

        Dim ds As New dsMasterAmlo
        Dim cls As New clsConnToDbByReport
        Dim re As rptMTSCTYPE3 = New rptMTSCTYPE3

        cls.rptMTscType3(re, strSql, ds)
        ReportViewer1.Report = re
    End Sub

#End Region

#Region "Master KYC"

    Sub MCUSTSUBTYPE()
        strSql = "   SELECT     MCUSTSUBTYPE.*" _
                 & "  FROM " & System.Configuration.ConfigurationSettings.AppSettings("TableMCUSTSUBTYPE") & " " _
                 & " order by CUSTSUBTYPE"
        Dim ds As New dsMasterKYC
        Dim cls As New clsConnToDbByReport
        Dim re As rptMCUSTSUBTYPE = New rptMCUSTSUBTYPE

        cls.rptMCustSubType(re, strSql, ds)
        ReportViewer1.Report = re

    End Sub

    Sub MMARITALSTATUS()
        strSql = "   SELECT     MMARITALSTATUS.* " _
                & "  FROM " & System.Configuration.ConfigurationSettings.AppSettings("TableMMARITALSTATUS") & " " _
                & " order by MARITALCODE"
        Dim ds As New dsMasterKYC
        Dim cls As New clsConnToDbByReport
        Dim re As rptMMARITALSTATUS = New rptMMARITALSTATUS

        cls.rptMMaritalStatus(re, strSql, ds)
        ReportViewer1.Report = re
    End Sub

    Sub MPOSITION()
        strSql = "   SELECT     MPOSITION.*" _
                & "  FROM " & System.Configuration.ConfigurationSettings.AppSettings("TableMPOSITION") & " " _
                & " order by POCODE"

        Dim ds As New dsMasterKYC
        Dim cls As New clsConnToDbByReport
        Dim re As rptMPOSITION = New rptMPOSITION

        cls.rptMPosition(re, strSql, ds)
        ReportViewer1.Report = re

    End Sub

    Sub MBIZRELATION()
        strSql = "   SELECT     MBIZRELATION.*" _
                 & "  FROM " & System.Configuration.ConfigurationSettings.AppSettings("TableMBIZRELATION") & " " _
                 & " order by BIZRECODE"
        Dim ds As New dsMasterKYC
        Dim cls As New clsConnToDbByReport
        Dim re As rptMBIZRELATION = New rptMBIZRELATION

        cls.rptMBizRelation(re, strSql, ds)
        ReportViewer1.Report = re
    End Sub

    Sub MBUSINESS()
        strSql = "   SELECT     MBUSINESS.*" _
                 & "  FROM " & System.Configuration.ConfigurationSettings.AppSettings("TableMBUSINESS") & " " _
                 & " order by BIZCODE"

        Dim ds As New dsMasterKYC
        Dim cls As New clsConnToDbByReport
        Dim re As rptMBUSINESS = New rptMBUSINESS

        cls.rptMBusiness(re, strSql, ds)
        ReportViewer1.Report = re
    End Sub

    Sub MCHECKEVIDENCE()
        strSql = "   SELECT     MCHECKEVIDENCE.*" _
                & "  FROM " & System.Configuration.ConfigurationSettings.AppSettings("TableMCHECKEVIDENCE") & " " _
                & " order by CHECKCODE,type"
        Dim ds As New dsMasterKYC
        Dim cls As New clsConnToDbByReport
        Dim re As rptMCHECKEVIDENCE = New rptMCHECKEVIDENCE

        cls.rptMCheckEvidence(re, strSql, ds)
        ReportViewer1.Report = re

    End Sub

    Sub MNATIONALITY()
        strSql = "   SELECT     MNATIONALITY.*" _
               & "  FROM " & System.Configuration.ConfigurationSettings.AppSettings("TableMNATIONALITY") & " " _
               & " order by NATIONCODE"
        Dim ds As New dsMasterKYC
        Dim cls As New clsConnToDbByReport
        Dim re As rptMNATIONALITY = New rptMNATIONALITY

        cls.rptMNationlity(re, strSql, ds)
        ReportViewer1.Report = re

    End Sub

    Sub MOCCUPATION()
        strSql = "   SELECT     MOCCUPATION.*" _
                 & "  FROM " & System.Configuration.ConfigurationSettings.AppSettings("TableMOCCUPATION") & " " _
                 & " order by OCCCODE,OCCTYPE"

        Dim ds As New dsMasterKYC
        Dim cls As New clsConnToDbByReport
        Dim re As rptMOCCUPATION = New rptMOCCUPATION

        cls.rptMOccupation(re, strSql, ds)
        ReportViewer1.Report = re

    End Sub

    Sub MPREFIX()
        strSql = "   SELECT     MPREFIX.*" _
                 & "  FROM " & System.Configuration.ConfigurationSettings.AppSettings("TableMPREFIX") & " " _
                 & " order by PREFIXCODE,PREFIXTYPE"

        Dim ds As New dsMasterKYC
        Dim cls As New clsConnToDbByReport
        Dim re As rptMPREFIX = New rptMPREFIX

        cls.rptMPrefix(re, strSql, ds)
        ReportViewer1.Report = re

    End Sub


#End Region

#End Region

#Region "reportKyc_Sanction"
    Private Sub Sanction_List(ByVal strLastUbdateDate As String, ByVal strDatasource As String, ByVal strSelectReport As String)
        Dim colVarParameter As Collection = New Collection
        Dim clsFormatDate As New clsDateFormat
        Dim StrWhere As String = ""
        Dim strConcat As String = " where "
        Dim strPrmCondition As String = ""
        Dim strWhere2 As String = ""


        Dim arrLastUbdateDate As String()
        Dim arrDatasource As String() = Nothing


        Dim strUpDate As String = ""
        Dim strSource As String = ""

        arrLastUbdateDate = Nothing
        arrLastUbdateDate = strLastUbdateDate.Split(";")

        If Not (arrLastUbdateDate(0) = "0") Then
            Dim strDate As String = ""
            Dim strSplitDateTime As String() = Nothing

            strDate = arrLastUbdateDate(0)
            strSplitDateTime = strDate.Split(" ")


            Dim dteStartDate As Date = clsFormatDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.En, strDate) & " " & strSplitDateTime(1)
            StrWhere = String.Format("{0}{1}IMPORT_DATE = :StartDate ", _
                                     StrWhere, _
                                     strConcat)
            strConcat = " And "

            clsVarParameter = New clsVariable() With {.nameColumn = "StartDate", _
                                                      .valueColumn = dteStartDate}
            colVarParameter.Add(clsVarParameter)

            strUpDate = strDate
            strWhere2 = strConcat & "lastUpdateDate = " & dteStartDate
            'If (strPrmCondition = "") Then
            '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtLastUpdate, strDate)
            'Else
            '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtLastUpdate, strDate)
            'End If

        Else
            strUpDate = " - "
            'If (strPrmCondition = "") Then
            '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtDate, "-")
            'Else
            '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtDate, "-")
            'End If
        End If


        arrDatasource = strDatasource.Split("|")
        If Not arrDatasource(0) = "0" Then


            strSource = arrDatasource(1)

            StrWhere = String.Format("{0}{1}FILE_TYPE = :datasource ", _
                                     StrWhere, _
                                     strConcat)
            strConcat = " And "
            clsVarParameter = New clsVariable() With {.nameColumn = "datasource", _
                                                      .valueColumn = strSource}
            colVarParameter.Add(clsVarParameter)
            strWhere2 = strConcat & "FILE_TYPE = " & strSource
            'If (strPrmCondition = "") Then
            '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtDatasource, arrDatasource(1))
            'Else
            '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtDatasource, arrDatasource(1))
            'End If
            ' strTempDataS = 
        Else
            strSource = " - "
            'If (strPrmCondition = "") Then
            '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtDatasource, "-")
            'Else
            '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtDatasource, "-")
            'End If
        End If

        Dim ds As New dsSanction
        Dim ds2 As New dsSanctionNew
        Dim cls As New clsConnToDbByReport


        Dim t As String = ""

        If (strSelectReport = "1") Then
            'strSql = "SELECT uniqueid,LASTUPDATEDATE,seq, FIRSTNAME, MIDDLENAME, LASTNAME, " _
            '    & "      FullName,COUNTRY, DATASOURCE, RISKLEVEL, comment1, comment2 " _
            '    & " FROM " & System.Configuration.ConfigurationSettings.AppSettings("Tableamllist_hist") & " " _
            '    & StrWhere _
            '    & " order by lastupdatedate,FIRSTNAME, LASTNAME "
            strSql = "select distinct m.INFO_SOURCE, m.ENTITY_ID, i.ID_VALUE ,n.original_script_name," &
                    " n.single_string_name,b.birthinfo_date,r.country_desc , m.stamp_dttm as lastupdate, ms.risklevel " &
                    " from  KYCADMIN.amlo_new_master_temp m   " &
                    " left join KYCADMIN.amlo_new_idnumber_temp i on m.entity_id = i.entity_id " &
                    " left join KYCADMIN.amlo_new_name_temp n  on m.entity_id = n.entity_id " &
                    " left join KYCADMIN.amlo_new_resident_temp r  on m.entity_id = r.entity_id " &
                    " left join KYCADMIN.amlo_new_birthinfo_temp b  on m.entity_id = b.entity_id and b.info_type = 1 " &
                    " left join KYCADMIN.amlo_new_import_temp im on im.importid = m.importid " &
                    " left join KYCADMIN.msanctionlist ms on ms.listtypecode =  im.file_type " & StrWhere

            If (strDatasource.ToLower.Contains("pep")) Then
                Dim re As rptSanctionFileUploadFull_Thai = New rptSanctionFileUploadFull_Thai
                cls.rptSanctionList(re, strSql, ds, colVarParameter)

                re.prmUpdateDate.Value = strUpDate
                re.prmDatasource.Value = strSource

                ' re.prmWhere.Value = strPrmCondition
                ReportViewer1.Report = re
            Else
                Dim re As New rptSanctionFileUploadFull2
                cls.rptSanctionListHistory(re, strSql, ds2, colVarParameter)
                re.prmUpDateDate.Value = strUpDate
                re.prmDataSource.Value = strSource
                ' re.prmWhere.Value = strPrmCondition
                ReportViewer1.Report = re
            End If

        ElseIf (strSelectReport = "0") Then
            'strSql = "   select lastupdatedate,seq,datasource " _
            '        & " from " & System.Configuration.ConfigurationSettings.AppSettings("Tableamllist_hist") & "  " _
            '        & StrWhere _
            '        & " order by lastupdatedate "  

            strSql = "SELECT DISTINCT IMPORT_DATE, FILE_TYPE" &
                    " FROM KYCADMIN.AMLO_NEW_IMPORT_TEMP " & StrWhere

            'Dim re As rptSanctionFileUpload = New rptSanctionFileUpload

         
            ''re.prmWhere.Value = strPrmCondition
            'ReportViewer1.Report = re
            Dim re As New rptSanctionFileUpload2

            re.prmUpdateDate.Value = strUpDate
            re.prmDatasource.Value = strSource

            'For i = 0 To 5
            '    Dim rowX = ds2.SANC_18TBL.NewSANC_18TBLRow()
            '    rowX.A = "001" & i
            '    rowX.B = "002"
            '    ds2.SANC_18TBL.AddSANC_18TBLRow(rowX)
            'Next

            'With (re)
            '    .DataSource = ds2.SANC_18TBL
            '    .DataMember = ds2.SANC_18TBL.TableName
            'End With


            'cls.rptSanctionList(re, strSql, ds, colVarParameter)
            cls.rptSanctionListHistory(re, strSql, ds2, colVarParameter)
            ReportViewer1.Report = re

        End If

     
    End Sub

    Private Sub AMLWatch_List(ByVal strListType As String)

        Dim colVarParameter As Collection = New Collection
        Dim StrWhere As String = ""
        Dim strConcat As String = " where "
        Dim strPrmCondition As String = ""


        Dim arrListType As String() = Nothing
        Dim re As rptWatchList2 = New rptWatchList2

        If Not strListType = "" Then
            arrListType = strListType.Split("/")
            If Not arrListType(0) = "0" Then
                StrWhere = String.Format("{0}{1}ListType = :ListType", StrWhere, strConcat)
                strConcat = " And "

                clsVarParameter = New clsVariable() With {.nameColumn = "ListType", _
                                                          .valueColumn = arrListType(0)}
                colVarParameter.Add(clsVarParameter)
                'If (strPrmCondition = "") Then
                '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtDept, arrListType(1))
                'Else
                '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtDatasource, arrListType(1))
                'End If
                re.prmSanctionList.Value = arrListType(1)
            Else
                re.prmSanctionList.Value = " ทั้งหมด "
                'If (strPrmCondition = "") Then
                '    strPrmCondition = strPrmCondition & String.Format(Resources.resPrintRptMaster.cdtDatasource, "-")
                'Else
                '    strPrmCondition = strPrmCondition & "   ;   " & String.Format(Resources.resPrintRptMaster.cdtDatasource, "-")
                'End If
            End If
        End If
      


        '        strSql = " SELECT CUSTCODE, DATEPROCESS, LASTUPDATELIST, CUSTTYPE, THFIRSTNAME, " _
        '                    & "   THMIDNAME, THLASTNAME, ENFIRSTNAME,ENMIDNAME, ENLASTNAME,LISTTYPE, RISKLEVEL,uniqueid " _
        '                & "  FROM " & System.Configuration.ConfigurationSettings.AppSettings("TableAMLWATCHLIST") & " " _
        '& StrWhere _
        ' & " order by THFIRSTNAME,THLASTNAME,ENFIRSTNAME,ENLASTNAME "

        strSql = "select * from KYCADMIN.Amlwatchlist2 a " & StrWhere & " order by THFIRSTNAME,THLASTNAME,ENFIRSTNAME,ENLASTNAME "

        Dim ds As New dsSanctionNew
        Dim cls As New clsConnToDbByReport

        cls.rptAmlWatchList2(re, strSql, ds, colVarParameter)
        re.prmWhere.Value = strPrmCondition
        ReportViewer1.Report = re

    End Sub

#End Region



End Class
